我只想在offset (0,6)
添加lastRow
。有什么帮助吗?
lastRow = oSht.Range(vari1 & Rows.Count).End(xlUp).Row
答案 0 :(得分:1)
在你澄清之后,我可以建议你可以通过范围扩展来做到这一点。您可以使用Offset
而不是Resize
。
正如您所说,这对您的S column
:
oSht.Range(vari2, vari1 & lastRow).Select
在我们添加调整大小后,您将获得新范围:
oSht.Range(vari2, vari1 & lastRow).Resize(,6).Select
答案 1 :(得分:0)
我认为这就是你想要的?
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