VBS Userform run time error

Mahmoudelnemr

New Member
Joined
May 14, 2019
Messages
5
Hello everyone,

I have userform named "operation" with several textboxes and command button named "cmdUpdate" this button to copy the boxes values after editing it to sheet named "DT" in an existing row it doesnt add new row

the code for this button as follow

Code:
Private Sub cmdUpdate_Click()
'update input values to sheet.
Sheets("DT").Unprotect Password:="bsm"
    Dim IRow As Long
    Dim TBRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("DT")
    IRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
    
.Cells(TBRow, 1).Value = Me.DE1.Value
.Cells(TBRow, 2).Value = Me.DE3.Value
.Cells(TBRow, 3).Value = Me.TextBox9.Value
.Cells(TBRow, 4).Value = Me.DE2.Value
.Cells(TBRow, 8).Value = Me.ComboBox1.Value
.Cells(TBRow, 9).Value = Me.TextBox8.Value
.Cells(TBRow, 7).Value = Me.DE8.Value
.Cells(TBRow, 5).Value = Me.DE6.Value
.Cells(TBRow, 6).Value = Me.DE7.Value

    End With
     Reset

Sheets("DT").Protect Password:="bsm"
End Sub

When i click the button error message says "run-time error 1004 application-defined or object-defined error" appears

any help with that
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
That's because you haven't given TBRow a value
 
Upvote 0
i found the below code in a sheet online and it works fine
so i customized to to my sheet, but didnt work for me

Code:
Private Sub cmdUpdate_Click()
'update input values to sheet.
    Dim lRow As Long
Dim TBrow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("DT")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
 
    With ws
        '.Cells(TBrow, 1).Value = Me.ComboBox1.Value
        .Cells(TBrow, 2).Value = Me.ComboBox8.Value
        .Cells(TBrow, 3).Value = Me.TextBox25.Value
        .Cells(TBrow, 4).Value = Me.TextBox24.Value
        .Cells(TBrow, 5).Value = Me.DTPicker1.Value
        .Cells(TBrow, 6).Value = Me.DTPicker2.Value
        .Cells(TBrow, 7).Value = Me.DTPicker3.Value
 
    End With
End Sub
 
Upvote 0
You need to give TBrow a value, at the moment it's 0 & there is no row 0 in the sheet hence the error.
 
Upvote 0
Change this

Code:
[B][COLOR=#ff0000]TBrow[/COLOR][/B][COLOR=#333333] = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top