Excel VBA Form Add data to a specific range

JJCam

New Member
Joined
Dec 28, 2018
Messages
6
Hi, I hope someone can help me out as I am really struggling with adding data from a user form to a specific range. Let's say I have a form (I just made up a real quick one for demonstration):
1725282741740.png

Where the Add Button basically sends the values of the textboxes into a specific range. If I rewrite a new ID, name and Job I want to fill the values on the following row and so on.

As per my sheet (also for reference), it would look like this and the yellow cells are the range where the values should go. This yellow range would be dynamic at the bottom.
1725282861007.png


I thought the easiest way would be to set up a starting range and then find the last empty row in column B but the empty row gives me error (I tried from different sources).

The code is:

Private Sub CommandButton1_Click()
Dim emptyRow As Long
Sheet1.Activate
emptyRow = .Range("B" & Rows.Count).End(xlUp).Row

Cells(emptyRow, 2).value = TextBox_ID.value
Cells(emptyRow, 3).value = TextBox_Name.value
Cells(emptyRow, 3).value = TextBox_Job.value
End Sub

I'd appreciate it if someone can shed the light. Thanks!

JJC
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
you have a period (full stop) in front of .Range which is not qualified to a worksheet object in your code.

As your sheet is the active sheet try changing that line for one below & see if resolves your issue

VBA Code:
emptyRow = Range("B" & Rows.Count).End(xlUp).Row + 1

Dave
 
Upvote 0
Solution
Thanks so much, that did the trick!
I cannot believe how easy it seemed and how much time I spent looping around to find a solution.
Thanks again!
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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