Simple question - Simple Solution - Last Row

erutherford

Active Member
Joined
Dec 19, 2016
Messages
458
I have a table with headers (starting in A1), nothing fancy. I have a form that controls the data that is entered, works fine.

If the table is empty with only the headers there, I get an error (at the Range statement). If cell A2 has something in it it works fine and finds the last row.

Code:
Private Sub CommandButton1_Click()
Range("A1").End(xlDown).Offset(1, 0).Select
'FN
If TextBox1.Value = "" Then
 
    MsgBox "First Name Required!", vbCritical
    UserForm1.TextBox1.SetFocus
    Exit Sub
 
End If

'LN
If TextBox2.Value = "" Then
 
    MsgBox "Last Name Required!", vbCritical
    UserForm1.TextBox2.SetFocus
    Exit Sub

End If

'US - Enters Data to Table
   
ActiveCell = TextBox1.Value 'FN
ActiveCell.Offset(0, 1) = TextBox2.Value 'LN

Unload UserForm2

End Sub

has to be something simple and I am looking right at it! Just don't see it!
 
Last edited by a moderator:
object -defined error still occurs at the first textBox1 value

<code>
LastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1)
Cells(LastRow, 1) = TextBox1.Value 'FN
Cells(LastRow, 2) = TextBox2.Value 'LN
Cells(LastRow, 3) = TextBox3.Value 'Add1
Cells(LastRow, 4) = TextBox4.Value 'Add2
Cells(LastRow, 5) = TextBox5.Value 'Add3
Cells(LastRow, 6) = TextBox6.Value 'City
Cells(LastRow, 7) = TextBox7.Value 'State
Cells(LastRow, 8) = TextBox8.Value 'Zip
Cells(LastRow, 9) = TextBox9.Value 'Country
Cells(LastRow, 10) = TextBox10.Value 'Email
Cells(LastRow, 11) = TextBox11.Value 'Ph1
Cells(LastRow, 12) = TextBox12.Value 'Ph2
Cells(LastRow, 13) = DTPicker1.Value 'Start Time
Cells(LastRow, 14) = DTPicker2.Value 'End Tme
Cells(LastRow, 15) = TextBox13.Value 'Notes
</code>

I also check to be sure Last Row was ID
Dim LastRow As Long
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You forgot the .Row:

Rich (BB code):
LastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
 
Upvote 0
Rory,
You were spot on, ".row" solved the issue. Just took a while to get back to the project. Thanks for sticking with me on this!

till next time.......
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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