excel 如何将范围(“A1:A11”)转换为(A“1:直到空单元格”)

ntjbwcob  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(289)

我试过只设置范围为(“A:A”),但这使表太大,我的计算机冻结了,我也试过输入像Range("A" & Rows.Count).End(xlUp).Offset(1)这样的行,但VBA不能识别。任何帮助都将不胜感激!

roejwanj

roejwanj1#

你需要首先通过引用列中的最后一个单元格来定义最后一行,然后使用.End(xlUp).row找到最后一个行号。然后你可以使用行号来构建单元格引用,或者甚至像我一样将范围保存为范围变量:

Sub Last_Row_Example()
    
    Dim LastRow As Long   'Last Row as a long integer
    Dim RG As Range       'A range we can reference again and again very easily
                          'Consider renaming it to something more descriptive.
                          'for your particular situation
    
    LastRow = Range("A" & Rows.Count).End(xlUp).Row ' Here we store the "LastRow" Number
    Set RG = Range("A1:A" & LastRow) ' Here we build a range using the LastRow variable.
        
    RG.Select
        Application.CutCopyMode = False
        ActiveSheet.ListObjects.Add(xlSrcRange, RG, , xlYes).Name = _
            "Table3"
        Range("Table3[[#All],[Ticker Name]]").Select
        Selection.ConvertToLinkedDataType ServiceID:=268435456, LanguageCulture:= _
            "en-US"
        
End Sub

相关问题