[英]Textbox.value as a variable
I need to copy an input in a textbox and transform this in a variable that will be used as a range. 我需要在文本框中复制输入并将其转换为将用作范围的变量。 With the code described below i'm facing error 91 Object variable or With block variable not set.
使用下面描述的代码,我遇到错误91对象变量或未设置块变量。 If you have a better way to do this, please let me know.
如果您有更好的方法来进行此操作,请告诉我。
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
The code is interesting. 该代码很有趣。 First, we are picking up
RangeboxA.value
. 首先,我们要选择
RangeboxA.value
。
To successfully use this within Range()
, it should look something like: 要在
Range()
成功使用它,它应该类似于:
A1:B9
but this kind of string will always fail IsNumeric()
so RangeA never gets Set
and the Select
will always fail. 但是这种字符串将始终失败
IsNumeric()
因此RangeA永远不会被Set
,而Select
将始终失败。
Now if RangeboxA.value
has a value like: 现在,如果
RangeboxA.value
具有类似的值:
17
then Isnumeric()
will be true, but then: 那么
Isnumeric()
将为true,但是:
Set rangeA = Sheets("Plan1").Range(RangeboxA.Value)
will fail. 将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.