我有一个宏,它选择我在 M 列中使用的第一个单元格(变量是 Firstrow)。此宏检测列 M 中使用的最后一个单元格(变量为 lastrow)。
我希望我的宏从 M 列中使用的第一个单元格到 M 列中使用的最后一个单元格进行选择。
我试过了:
范围 (Firsttrow & "M:M" & lastrow)
但我收到一条错误消息
“编译错误:无效使用属性”
Sub Selectfromfirstrowusedtolastrowusedused()
Dim lastrow, Firstrow As Long
lastrow = ActiveSheet.Range("M" & Rows.Count).End(xlUp).Row
Firstrow = Range("M1").End(xlDown).Row
Debug.Print Firstrow
Debug.Print lastrow
Range (Firsttrow & "M:M" & lastrow)
End Sub
你需要
Range("M" & Firsttrow & ":M" & lastrow).Select
因为它是使用范围的列然后行。另一种选择是
Range(cells(firstrow,"M"),cells(lastrow,"M")).Select
并不是说你很少需要选择任何东西。
此外,在这一行
Dim lastrow, Firstrow As Long
lastrow 被声明为一个变体,所以最好做
Dim lastrow As Long, Firstrow As Long
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句