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
--
Regards,
Tom Ogilvy
"Chris" wrote:
> 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
>
|