我有一个范围可以调整大小,我想知道是否有办法使调整大小更具体。即.Resize(,7)
将是B-G列但我只想要B,F,G列。
这是我正在使用的线路。
a = .Range("b2", .Range("b" & Rows.Count).End(xlUp)).Resize(, 7).Value
Private Sub TextBox_Search_Change()
Select Case True
Case OptionButton_User_Name.Value
Dim a, i As Long, ii As Long, n As Long, temp As String
If Len(Me.TextBox_Search.Value) Then
temp = UCase(Me.TextBox_Search.Value)
With Sheets("ToolData")
a = Union(.Range("B:B"), .Range("F:F"), .Range("G:G")).Value
End With
a = Application.Transpose(a)
For i = 1 To UBound(a, 2)
If UCase(a(1, i)) Like "*" & temp & "*" Or _
UCase(a(2, i)) Like "*" & temp & "*" Then
n = n + 1
For ii = 1 To UBound(a, 1)
a(ii, n) = a(ii, i)
Next
End If
Next
If n > 0 Then
ReDim Preserve a(1 To UBound(a, 1), 1 To n)
Me.ListBox_History.Column = a
End If
Else
With Sheets("ToolData")
Me.ListBox_History.List = .Range("b2", .Range("b" & Rows.Count).End(xlUp)).Resize(, 7).Value
End With
End If
Case Else
End Select
End Sub
答案 0 :(得分:4)
Union
可能是个好地方。在一个简单的例子中,它可以像你这样工作:
Dim r as Range
With ThisWorkbook.Worksheets("Sheet1")
Set r = Union(.Range("B:B"),.Range("F:F"),.Range("G:G"))
End With