Hello
I try copying data from userform based on combobox to selected sheet but it gives error when press commandbutton1
object variable or with block in this line
the whole code
any help guys,please?
I try copying data from userform based on combobox to selected sheet but it gives error when press commandbutton1
object variable or with block in this line
VBA Code:
Set myrange = sh.Columns(2).Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
VBA Code:
Private Sub CommandButton1_Click()
Dim Name As String
Dim sh As Worksheet
Dim myrange As Range
Dim i As Long
For i = 2 To Sheets.Count
Me.ComboBox1.AddItem Sheets(i).Name
If Me.ComboBox1.Value = "" And Me.ComboBox1.ListIndex = -1 Then Exit Sub
If Me.ComboBox1.Value <> "" Then
Set myrange = sh.Columns(2).Find(ComboBox1, LookIn:=xlValues, lookat:=xlWhole)
If Not myrange Is Nothing Then
With myrange
.Offset(, 1) = TextBox1.Value
.Offset(, 2) = TextBox2.Value
End With
End If
End If
Next
End Sub
VBA Code:
Private Sub UserForm_Initialize()
Dim i As Long
For i = 2 To Sheets.Count
Me.ComboBox1.AddItem Sheets(i).Name
Next i
End Sub