2 Command Buttons - 1 works, 1 doesn't

scwisely

New Member
Joined
Jun 21, 2019
Messages
22
Hi All,
Need some help, I have 2 user forms that I am using to add data to a list. 1 of the VBA codes works fine, so I copied it and changed the cells and assigned it to another user form command button (commandbutton11) however, this one that i copied is not working and stops working at line "LastrowBZ = Sheets(SN).Cells(Rows.Count, "BZ").End(xlUp).Row + 1" Can someone help me fix this ....

Here's the code that DOES NOT work:
Code:
Private Sub CommandButton11_Click()'Modified  6/22/2019  2:19:53 AM  EDT
Dim SN As String
SN = Range("E4").Value
Dim LastrowBZ As Long
LastrowBZ = Sheets(SN).Cells(Rows.Count, "BZ").End(xlUp).Row + 1
If LastrowBZ < 138 Then LastrowBZ = 138
Dim LastrowCB As Long
LastrowCB = Sheets(SN).Cells(Rows.Count, "CB").End(xlUp).Row + 1
If LastrowCB < 138 Then LastrowCB = 138
Sheets(SN).Cells(LastrowAZ, "BZ").Value = TextBox1.Value
Sheets(SN).Cells(LastrowBB, "CB").Value = TextBox2.Value
With Sheets(SN)
.Range("CA138").Value = ActiveSheet.Range("E4").Value & .Range("BZ138").Value
End With
End Sub

Here's the original code that works, that I copied and pasted

Code:
Private Sub CommandButton1_Click()'Modified  6/22/2019  2:19:53 AM  EDT
Dim SN As String
SN = Range("E4").Value
Dim LastrowAZ As Long
LastrowAZ = Sheets(SN).Cells(Rows.Count, "AZ").End(xlUp).Row + 1
If LastrowAZ < 160 Then LastrowAZ = 160
Dim LastrowBB As Long
LastrowBB = Sheets(SN).Cells(Rows.Count, "BB").End(xlUp).Row + 1
If LastrowBB < 160 Then LastrowBB = 160
Sheets(SN).Cells(LastrowAZ, "AZ").Value = TextBox1.Value
Sheets(SN).Cells(LastrowBB, "BB").Value = TextBox2.Value
With Sheets(SN)
.Range("BA160").Value = ActiveSheet.Range("E4").Value & .Range("AZ160").Value
End With
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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