我正在尝试将 Last column 用于我的范围:WS.range("F2:LastCol" & LastRow).Cells
我的 sub 适用于
WS.range("F2:K" & LastRow).Cells
但它Last Column
是动态的并且不断变化
谢谢
Sub QQ()
Dim LastRow As Long
Dim LastCol As Long
Dim WS As Worksheet
Dim rCell As range
Set WS = Sheets("sheet1")
LastRow = WS.range("F" & WS.Rows.Count).End(xlUp).Row
LastCol = Cells(2, .Columns.Count).End(xlToLeft).Column
'Also tried: LastCol=rgRange.Cells(rgRange.Count).Column
For Each rCell In WS.range("F2:LastCol" & LastRow).Cells
STUFF 'The stuff works for WS.range("F2:K" & LastRow).Cells
End Sub