Add User from a UserForm

G

Guest

I'm trying to add a user via an UserForm. I've been using this code for
ComboBoxes but it errors out for my textbox. When it runs, the error message
is

"Run-time error '1004': Method 'Range' of object '_Worksheet' failed"
The debugger points to this line
Sheet2.Range("H" & found).Value = UserForm1.TextBox9.Value

I can't find out why 'found' doesn't have a value. Any thoughts. The full
code is below.



Private Sub CommandButton12_Click()

'Add new user

test_row = 2
test_value = Sheet2.Range("H" & test_row).Value

While test_value <> ""
If test_value = UserForm1.TextBox9.Value Then
found = test_row
GoTo leaveloop1
End If
test_row = test_row + 1
test_value = Sheet2.Range("H" & test_row).Value
Wend

leaveloop1:

Sheet2.Range("H" & found).Value = UserForm1.TextBox9.Value

ComboBoxRefresh

End Sub
 
G

Guest

Private Sub CommandButton12_Click()

'Add new user

test_row = 2
test_value = Sheet2.Range("H" & test_row).Value

While test_value <> ""
If test_value = UserForm1.TextBox9.Value Then
found = test_row
GoTo leaveloop1
End If
test_row = test_row + 1
test_value = Sheet2.Range("H" & test_row).Value
Wend

leaveloop1:
if found > 1 then
Sheet2.Range("H" & found).Value = UserForm1.TextBox9.Value
else
Sheet2.Range("H" & Test_Row).Value = UserForm1.TextBox9.Value
End if
ComboBoxRefresh

End Sub
 
G

Guest

Wahoo! That worked thanks!

Tom Ogilvy said:
Private Sub CommandButton12_Click()

'Add new user

test_row = 2
test_value = Sheet2.Range("H" & test_row).Value

While test_value <> ""
If test_value = UserForm1.TextBox9.Value Then
found = test_row
GoTo leaveloop1
End If
test_row = test_row + 1
test_value = Sheet2.Range("H" & test_row).Value
Wend

leaveloop1:
if found > 1 then
Sheet2.Range("H" & found).Value = UserForm1.TextBox9.Value
else
Sheet2.Range("H" & Test_Row).Value = UserForm1.TextBox9.Value
End if
ComboBoxRefresh

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top