0

我正在尝试在 EXCEL/VBA 中创建一个用户表单,一旦选择了命令按钮“预测”,它将允许您选择数据范围并将数据范围复制到特定工作表,具体取决于标签条索引。

到目前为止,这是我对 tabstrip 所做的更改:

Private Sub tbsMethod_Change()
Dim tabIndex As Integer
tabIndex = tbsMethod.SelectedItem.Index
Select Case tabIndex
Case 0
Label2.Visible = True
RefEdit1.Visible = True
Label_a.Visible = False
Label_b.Visible = False
Label_g.Visible = False
TextBox_a.Visible = False
TextBox_b.Visible = False
TextBox_g.Visible = False
Case 1
Label2.Visible = True
....

这就是我认为问题所在(commandbutton_click):

Sub ForecastButton_Click()
Dim tabIndex As Integer
Dim ws As Worksheet
tabIndex = tbsMethod.SelectedItem.Index
With ThisWorkbook
Select Case tabIndex
'copies to worksheet or "module"
Case 0
Application.GoTo ActiveWorkbook.Sheets("Sheet1").Range("B7")
Range(RefEdit1.Value).Copy Destination:=Sheet1.Range("B7:B26")
Case 1
Range(RefEdit1.Value).Copy Destination:=Sheet3.Range("B7:B26")
Application.GoTo ActiveWorkbook.Sheets("Sheet3").Range("B7")
Case 2
Application.GoTo ActiveWorkbook.Sheets("Sheet4").Range("B7")
.Cells(29, 2).Value = Me.TextBox_a.Value
Range(RefEdit1.Value).Copy Destination:=Sheet4.Range("B7:B26")
Case 3
Application.GoTo ActiveWorkbook.Sheets("Sheet5").Range("B7")
.Cells(29, 2).Value = Me.TextBox_a.Value
.Cells(30, 2).Value = Me.TextBox_b.Value
Range(RefEdit1.Value).Copy Destination:=Sheet5.Range("B7:B26")

Case 4
Application.GoTo ActiveWorkbook.Sheets("Sheet6").Range("B7")
.Cells(29, 2).Value = Me.TextBox_a.Value
.Cells(30, 2).Value = Me.TextBox_b.Value
.Cells(31, 2).Value = Me.TextBox_g.Value
Range(RefEdit1.Value).Copy Destination:=Sheet6.Range("B7:B26")

End Select
Unload dfMod
End With

Me.R.Value = ""
Private Sub cmdClose_Click()
    Unload dfMod
End Sub

我收到错误消息“错误 9 下标超出范围”。现在它说“找不到方法或数据成员”。VBA/EXCEL 相当新,所以任何帮助将不胜感激

谢谢,瑞安

4

1 回答 1

1

你的代码中有

With thisworkbook
    ...
    .cells(...

cells不是workbook对象的属性或方法,将返回错误

于 2013-03-21T08:49:25.933 回答