Add entry at the end of a list with a UserForm

Allan91

New Member
Joined
Dec 17, 2020
Messages
33
Office Version
  1. 2019
Platform
  1. Windows
Hi guys,

I am trying to write a code within a userform which can be used to enter data on 3 columns. The columns are F, G, H and the row start from row 4. But when I try to run the code I get an object error on ActiveSheet.Cells(lastrow + 1, 6).Value = TextBox1.Value. I'm new to VBA so the whole code could be wrong but I'm pretty sure there's a small fix I need. Please see an image of the userform and target range I have created as well. "TargetSheet" is a combo box I have created with items with names of sheets I want the data to be copied. CommandButton1 is the "Save Entry" button.

Thank you very much already!

VBA Code:
Private Sub CommandButton1_Click()

Targetsheet = ComboBox1.Value
If Targetsheet = "" Then
Exit Sub
End If
Worksheets(Targetsheet).Activate
lastrow = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
ActiveSheet.Cells(lastrow + 1, 6).Value = TextBox1.Value
ActiveSheet.Cells(lastrow + 1, 7).Value = TextBox2.Value
ActiveSheet.Cells(lastrow + 1, 8).Value = TextBox3.Value
MsgBox ("Data entry is successful!")

End Sub
 

Attachments

  • UserForm.PNG
    UserForm.PNG
    4.1 KB · Views: 11
  • Target Range.PNG
    Target Range.PNG
    7.9 KB · Views: 12

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Do you have a textbox called textbox1 or have you renamed it?
 
Upvote 0
Solution
Do you have a textbox called textbox1 or have you renamed it?
Yes that was my problem Fluff. Apparently my problem was the textbox name. Thank you very much! But this surfaced another problem. The code starts counting from row 1. I need it to start counting from row 4. But this is a different problem. Maybe I should start a new thread for this?
 
Upvote 0
As you are putting the values into col F why not use that column to find the next blank row
VBA Code:
lastrow = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row
 
Upvote 0
As you are putting the values into col F why not use that column to find the next blank row
VBA Code:
lastrow = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row
You are right!. Thank you a bunch Fluff!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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