[英]Object Required: VBA Excel, Range selection
So I am getting an error in this line of code in this particular selection structure I am trying to formulate. 因此,在我要制定的这种特定选择结构中,这一行代码出现错误。 I am trying to dynamically select a range based off of the selection of Demand and a user entry that gets read into UB, However I keep getting the object required error and am sure what is wrong (I know my code is a bit redundant at a certain part, I was getting an another error code about range and left some of the redundancies for now!) 我试图根据需求的选择和被读入UB的用户条目动态选择一个范围,但是我不断收到对象必需的错误,并确定出了什么问题(我知道我的代码有点多余某些部分,我得到了关于范围的另一个错误代码,并且现在暂时保留了一些冗余!)
Dim y As Integer
UB = TextBox1.Text
y = UB + 4
srange = "C" & 4 & ":" & "J" & y
If ComboBox2.Text = "Demand" Then
Worksheets("SensitivityDemand").Visible = True
Worksheets("Welcome").Visible = False
Worksheets("SensitivityDemand").Activate
ActiveSheet.Range("A1").Select
Sheets("SensitivityDemand").Select
With ActiveSheets
.Range("srange").Select 'Object required here
Application.CutCopyMode = False
'Application.CutCopyMode = False
Selection.Table RowInput:=Range("B3"), ColumnInput:=Range("B4")
Can you try this below code and let me know if there is any thing missing. 您可以在下面的代码中尝试一下,让我知道是否缺少任何内容。
Dim y As Integer
UB = TextBox1.Text
y = UB + 4
srange = "C" & 4 & ":" & "J" & y
If ComboBox2.Text = "Demand" Then
Worksheets("SensitivityDemand").Visible = True
Worksheets("Welcome").Visible = False
Worksheets("SensitivityDemand").Activate
ActiveSheet.Range("A1").Select
'Sheets("SensitivityDemand").Select
ActiveSheet.Range(srange).Select 'Object required here
Application.CutCopyMode = False
'Application.CutCopyMode = False
Selection.Table RowInput:=Range("B3"), ColumnInput:=Range("B4")
Do no use the ActiveSheets Also srange
do not put those in double qoutes as it has some values passed to it. 难道没有用ActiveSheets也srange
不要把那些双qoutes因为它传递给它一些值。 So if you put srange
in double qoutes it will treat as a string not a value. 所以,如果你把srange
双qoutes它将把一个字符串不是一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.