我需要在一個文本框中複製一個輸入,並將其轉換爲一個將用作範圍的變量。使用下面描述的代碼,我正面臨錯誤91對象變量或未設置塊變量。如果你有更好的方式來做到這一點,請讓我知道。Textbox.value作爲變量
Private Sub CommandButton1_Click()
Dim rng As String
Dim rangeA As Range
Dim rangeB As Range
Dim rangeC As Range
Dim rangeD As Range
Dim rangeE As Range
rng = TextBoxA.Value
If IsNumeric(RangeboxA.Value) Then
On Error Resume Next
Set rangeA = Sheets("Plan1").Range(RangeboxA.Value)
On Error GoTo 0
If rangeA Is Nothing Then MsgBox "Range A inválido"
End If
rangeA.Select
Selection.Cut
rangeA.Offset(0, rng).Select
ActiveSheet.Paste
rng = TextBoxB.Value
Range("B3:E3").Select
Selection.Cut
Range("B3").Offset(0, rng).Select
ActiveSheet.Paste
rng = TextBoxC.Value
Range("B4:E4").Select
Selection.Cut
Range("B4").Offset(0, rng).Select
ActiveSheet.Paste
rng = TextBoxD.Value
Range("B5:E5").Select
Selection.Cut
Range("B5").Offset(0, rng).Select
ActiveSheet.Paste
rng = TextBoxE.Value
Range("B6:E6").Select
Selection.Cut
Range("B6").Offset(0, rng).Select
ActiveSheet.Paste
Me.Hide
End Sub
什麼將被輸入到文本框? – Kyle