Excel 将偏移量添加到最后一行

Excel 将偏移量添加到最后一行,excel,vba,Excel,Vba,我只想在我的lastRow中添加一个偏移量(0,6)。有什么帮助吗 lastRow = oSht.Range(vari1 & Rows.Count).End(xlUp).Row 我想这就是你想要的 Option Explicit Sub Sample() Dim oSht As Worksheet Dim lastRow As Long Dim Rng As Range Dim vari1 As String '~~> Change t

我只想在我的
lastRow
中添加一个
偏移量(0,6)
。有什么帮助吗

lastRow = oSht.Range(vari1 & Rows.Count).End(xlUp).Row

我想这就是你想要的

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

在你澄清之后,我可以建议你扩大范围。您可以使用
Resize
代替
Offset

正如您所说,这对于您的
S列来说是正确的:

oSht.Range(vari2, vari1 & lastRow).Select
在添加“调整大小”后,您将获得新的范围:

oSht.Range(vari2, vari1 & lastRow).Resize(,6).Select

你说的偏移到最后一行是什么意思?或者您的意思是
vari1