使用选择案例
Sub test()
myInteger = 1
Select Case myInteger
Case 1
X = ThisWorkbook.Sheets("Sheet").Range("B3:B253")
Y = ThisWorkbook.Sheets("Sheet").Range("C3:C253")
Case 2
X = ThisWorkbook.Sheets("Sheet").Range("D3:D253")
Y = ThisWorkbook.Sheets("Sheet").Range("E3:E253")
Case Else
X = ThisWorkbook.Sheets("Sheet").Range("D3:D253")
Y = ThisWorkbook.Sheets("Sheet").Range("E3:E253")
End Select
End Sub
使用 If...Else..
Sub test()
myInteger = 1
If myInteger = 1 Then
X = ThisWorkbook.Sheets("Sheet").Range("B3:B253")
Y = ThisWorkbook.Sheets("Sheet").Range("C3:C253")
ElseIf myInteger = 2 Then
X = ThisWorkbook.Sheets("Sheet").Range("D3:D253")
Y = ThisWorkbook.Sheets("Sheet").Range("E3:E253")
Else
X = ThisWorkbook.Sheets("Sheet").Range("D3:D253")
Y = ThisWorkbook.Sheets("Sheet").Range("E3:E253")
End If
End Sub