Use Last Column for a Range(F:LastColumn)

前端 未结 3 765
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 01:19

I am trying to use Last column for my range: WS.range(\"F2:LastCol\" & LastRow).Cells my sub works for

WS.range(\"F2:K\" & LastRow).Cells

3条回答
  •  逝去的感伤
    2021-01-21 01:53

    Please try to define your loop this way:

    For Each rCell In WS.range(ws.Range("F2"), Ws.Cells(LastRow, LastCol)).Cells
    

    or it could go shorter way with this solution (if WS is Activesheet):

    For Each rCell In WS.range("F2", Cells(LastRow, LastCol)).Cells
    

提交回复
热议问题