user form deletes first row contents of table

Project217

New Member
Joined
Mar 7, 2022
Messages
24
Office Version
  1. 365
Platform
  1. MacOS
HI All.

I am trying to add a user form to an excel data table with formulas, I have managed to get the user form to add the data to the table, however it keeps over writing the data on the first row of the data table and not inputting it on there next available row, Can you please help me with this?

This is the VBA I have used.

Private Sub CommandButton1_Click()

Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("Master Sheet")
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
With ws
.Range("D4") = TextBox4.Value
.Range("R4") = TextBox5.Value
.Range("C4") = TextBox6.Value
End With
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""


End Sub

Any help on this would be awesome! Thanks.

Rory.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
In that case you would need to use
Rich (BB code):
Lrow = ws.Cells(Rows.count, 2).End(xlUp).Offset(1, 0).Row
assuming that col B will always have a value.
 
Upvote 0
No not in master sheet or sheet 1

In that case you would need to use
Rich (BB code):
Lrow = ws.Cells(Rows.count, 2).End(xlUp).Offset(1, 0).Row
assuming that col B will always have a value.
It worked, But it stores the data in rows from 99992,9993 ect.
 

Attachments

  • VBA.PNG
    VBA.PNG
    8.1 KB · Views: 7
Upvote 0
In that case clear all cells in column B below the last used row.
 
Upvote 0
Thank you! That works perfectly, except how do i get it to automatically add the data in my data table "Table2"?
 
Upvote 0
How about
VBA Code:
Private Sub CommandButton1_Click()

Dim NxtRw As ListRow
Dim ws As Worksheet
Set ws = Worksheets("Master Sheet")
'find first row in database
Set NxtRw = ws.ListObjects("Table2").ListRows.Add
With NxtRw
   .Range(4) = TextBox4.Value
   .Range(17) = TextBox5.Value
   .Range(1) = TextBox6.Value
End With
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""


End Sub
 
Upvote 0
Your a legend Fluff! worked perfectly. but I think when I changed the code to allow my new cell locations I have done something wrong, it now adds the "Name:" text box value 5 into the "Ordered By:" column one row below the rest (See pic attached) I have also attached the line of code you sent me with my changes (so you can hopefully see where I've made the mistake)
Thanks so much for your help.
 

Attachments

  • Order form.PNG
    Order form.PNG
    33.9 KB · Views: 7
  • VBA 2.PNG
    VBA 2.PNG
    14.5 KB · Views: 7
Upvote 0
What column should it be in? from the code you originally posted it looks as though it should be in Col R, in which case use the code in post#18
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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