用VBA划分每一行

时间:2013-09-06 05:46:06

标签: excel-vba vba excel

我试图将每一行划分到最后一行,但我只是被划分为一行,即第2行。我正在考虑使用这个

Dim LastRow As Range

LastRow = Range("A" & Rows.Count).End(xlUp).Row

但我对如何使用该系列的知识非常有限。

分享你的想法..谢谢! :)

我的代码如下:

Sub test1()


For Each c In Range("AL2:AS2 , BC2 ")
c.Value = c.Value / 1000
Next c

End Sub

1 个答案:

答案 0 :(得分:1)

您可以通过构建范围字符串来构建范围,如下所示:

Range("AL2:AS" & LastRow & ", BC2:BC" & LastRow)

请注意,Range的.Row属性返回Long这是行号,因此您必须声明:

 Dim LastRow As Long

最后这给出了:

Sub test2()

 Dim LastRow As Long
 Dim myCell As Range

 LastRow = Range("A" & Rows.Count).End(xlUp).Row

 For Each myCell In Range("AL2:AS" & LastRow & ", BC2:BC" & LastRow)
  myCell.Value = myCell.Value / 1000
 Next myCell
End Sub
相关问题