ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add User from a UserForm (https://www.excelbanter.com/excel-programming/377413-add-user-userform.html)

Chris

Add User from a UserForm
 
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


Tom Ogilvy

Add User from a UserForm
 
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


Chris

Add User from a UserForm
 
Wahoo! That worked thanks!

"Tom Ogilvy" wrote:

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



All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com