Vba 在Excel中使用变量选择多个单元格
如果要使用VBA在Excel中选择多个单元格,请执行以下操作:Vba 在Excel中使用变量选择多个单元格,vba,excel,Vba,Excel,如果要使用VBA在Excel中选择多个单元格,请执行以下操作: range("A1:B4").Select 如果我的行是变量的值,我不知道如何选择这些单元格 有人知道怎么做吗?以下是当前所选工作表的示例: Sub test() TopRow = 1 BottomRow = 10 LeftColumn = 3 RightColumn = 9 Range(Cells(TopRow, LeftColumn), Cells(BottomRow, RightCol
range("A1:B4").Select
如果我的行是变量的值,我不知道如何选择这些单元格
有人知道怎么做吗?以下是当前所选工作表的示例:
Sub test()
TopRow = 1
BottomRow = 10
LeftColumn = 3
RightColumn = 9
Range(Cells(TopRow, LeftColumn), Cells(BottomRow, RightColumn)).Select
End Sub
对于某些特定的表:
Sub test()
SheetName = "Test"
TopRow = 1
BottomRow = 10
LeftColumn = 3
RightColumn = 9
With Sheets(SheetName)
.Select
.Range(.Cells(TopRow, LeftColumn), .Cells(BottomRow, RightColumn)).Select
End With
End Sub
间接(你的细胞)?你也可以依靠这种方法。例如:Dim CellFrom As String Dim CellTo As String CellFrom=“A1”和CellTo=“B4”您可以执行以下操作:范围(CellFrom&“:”&CellTo)。选择。您也可以通过索引访问列/行(索引是基于1的,但不是VBA中的所有内容,它与VB.NET和Excel无关,默认情况下是基于1的->我正在澄清这一点,因为我刚才对此进行了长时间的讨论:)。有很多选择。也许您应该看看一些基本的示例代码。这很有效,谢谢