VBA,带有工作表和范围

问题描述

我不想将工作表名称放在每个范围的前面,我正尝试使用With Worksheets使其更整洁,但它将另一个工作表保留给我的代码。

有什么想法吗?

With Worksheets("Step 4 CM")
aLastRow = .Range("D" & .Rows.Count).End(xlUp).Row
Range("A10:A" & aLastRow).Formula = "=$A$6"
Range("C10:C" & aLastRow).FillDown
Range("E10:E" & aLastRow).FillDown

bLastRow = .Range("L" & .Rows.Count).End(xlUp).Row
Range("I10:I" & bLastRow).Formula = "=$A$6"
Range("K10:K" & bLastRow).FillDown
Range("M10:M" & bLastRow).FillDown

cLastRow = .Range("S" & .Rows.Count).End(xlUp).Row
Range("P10:P" & cLastRow).Formula = "=$A$6"
Range("R10:R" & cLastRow).FillDown
Range("T10:T" & cLastRow).FillDown


End With

解决方法

使用with语句时,请在子引用前面使用点

所以:

With Worksheets("Step 4 CM")
.Range("T10:T" & cLastRow).FillDown
End With

并在所有范围引用中使用它。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...