我試圖用最後一欄爲我的範圍:WS.range("F2:LastCol" & LastRow).Cells
我的子作品使用最後一列的範圍(F:LastColumn)
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
你好飲食負責人,不知道如何將你的代碼應用到我的Sub。我可以在'Set rng = ws.Range(startCol&startRow&「:」&myCol&lastRow)''之後添加我的子集的'innerds',或者我可以使用'rng = ws.Range(startCol&startRow&「: &myCol&lastRow)'在我的sud。謝謝 – xyz
當你定義一個範圍時,你總是需要'set'關鍵字。我不確定我完全理解你的問題。我編輯了我的答案,包括你的循環。這有幫助嗎? –
是的,這是回答我的問題,我會嘗試使用它,我會回報。謝謝 – xyz