我只想offset (0,6)
在我的lastRow
. 有什么帮助吗?
lastRow = oSht.Range(vari1 & Rows.Count).End(xlUp).Row
在您澄清之后,我可以建议您可以通过范围扩展来做到这一点。而不是Offset
你可以使用Resize
.
正如你所说,这对你的工作是正确的S column
:
oSht.Range(vari2, vari1 & lastRow).Select
在我们添加调整大小后,您将获得新的范围:
oSht.Range(vari2, vari1 & lastRow).Resize(,6).Select
我想这就是你想要的?
Option Explicit
Sub Sample()
Dim oSht As Worksheet
Dim lastRow As Long
Dim Rng As Range
Dim vari1 As String
'~~> Change this to the relevant column letter
vari1 = "S"
'~~> Change this to the relevant sheet
Set oSht = ThisWorkbook.Sheets("Sheet1")
With oSht
lastRow = .Range(vari1 & .Rows.Count).End(xlUp).Row
Set Rng = .Range(vari1 & 2 & ":" & .Range(vari1 & lastRow).Offset(, 6).Address)
'~~> S2:X32 in your case if lastrow is 32
Debug.Print Rng.Address
End With
End Sub