Excel用户窗体comboboxselect工作表来放入值

嗨,我想在用户input的信息,并可以select工作表,他们想要的信息input到该电子表格Excel的用户表单编程。

这是我迄今为止。

Dim iRow As Long Dim sheet As String sheet = ComboBox1.Value Worksheets(sheet).Activate iRow = sheet.Cells.Find(what:="*", seatchOrder:=xlRows, searchdirection:=xlPrevious, LookIn:=xlValues).Row + 1 

当我运行用户窗体,并在combobox中select工作表,并点击命令button来运行窗体,我得到错误“无效限定符”

它突出了sheet.cells

这里是整个代码,如果有帮助:

  Private Sub ComboBox1_Change() End Sub Private Sub CommandButton1_Click() 'get item button Dim sheet As String UserForm8.Hide MsgBox ("Select an item to update") sheet = ComboBox1.Value Worksheets(sheet).Activate Set ProjRng = Application.InputBox(Message, Title, "", 377, 58, , , 8) ProjSel = ProjRng.Cells.Row Label1.Enabled = True Label2.Enabled = True Label3.Enabled = True Label4.Enabled = True Label8.Enabled = True Label10.Enabled = True TextBox1.Enabled = True TextBox2.Enabled = True TextBox3.Enabled = True TextBox4.Enabled = True TextBox8.Enabled = True TextBox10.Enabled = True TextBox10.Locked = False CommandButton1.Enabled = True ComboBox1.Enabled = True UserForm8.TextBox1.Value = ActiveSheet.Cells(ProjSel, 1).Value UserForm8.TextBox2.Value = ActiveSheet.Cells(ProjSel, 2).Value UserForm8.TextBox3.Value = ActiveSheet.Cells(ProjSel, 3).Value UserForm8.TextBox4.Value = ActiveSheet.Cells(ProjSel, 4).Value UserForm8.TextBox8.Value = ActiveSheet.Cells(ProjSel, 8).Value UserForm8.TextBox11.Value = ActiveSheet.Cells(ProjSel, 6).Value UserForm8.Show End Sub Private Sub CommandButton2_Click() 'Update button to update the remaing quantity amount Dim iRow As Long Dim sheet As String sheet = ComboBox1.Value Worksheets(sheet).Activate iRow = sheet.Cells.Find(what:="*", seatchOrder:=xlRows, searchdirection:=xlPrevious, LookIn:=xlValues).Row + 1 With Worksheets("ChemLog") .Cells(iRow, 6).Value = Me.TextBox12 End With With sheet .Cells(iRow, 1).Value = Me.TextBox1.Value end with 'continue above with columns according to log End Sub Private Sub TextBox10_Change() End Sub Private Sub TextBox11_Change() End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() ComboBox1.AddItem ("Standards") ComboBox1.AddItem ("Acids,Bases, and Buffers") ComboBox1.AddItem ("Solvents and Flammables") End Sub 

和拼写错误一样, sheet也是一个string,所以它需要:

 Worksheets(sheet).Cells.Find(.. 

这是您收到特定错误消息的原因。