VBA Excel-选择列中而不是整个列中的数据使用范围

时间:2018-07-24 17:49:04

标签: excel-vba

请参见下面的代码。我试图选择列数据,而不是整个列。因此,可能只是想将代码更改为“ UsedRange”? 感谢您的协助!

'Select entire column-need to select only USED RANGE

Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xStr As String
On Error Resume Next
xStr = "FEE RATE"
Set xRg = Range("A1:AA1").Find(xStr, , xlValues, xlWhole, , , True)
If Not xRg Is Nothing Then
    xFirstAddress = xRg.Address
    Do
        Set xRg = Range("A1:AA1").FindNext(xRg)
        If xRgUni Is Nothing Then
            Set xRgUni = xRg
        Else
            Set xRgUni = Application.Union(xRgUni, xRg)
        End If
    Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
xRgUni.EntireColumn.Select

0 个答案:

没有答案