Creating a list of data using a command button

Cazzdevil

New Member
Joined
Jul 18, 2014
Messages
10
Hi everyone, really hoping you can help me on this one.

I'm creating a new Time in Motion sheet for my team, and I want to programme a Command Button so that when it's clicked on Sheet 1 it prompts for a reference number to be input, then that reference number is fed into (say) column D on Sheet 2, but then when the button is clicked again it adds the next reference number to the next empty row down in the column gradually generating a list.

The idea is that we have 8 different tasks performed throughout the day multiple times each so I want to create a list of the cases worked on for each task.

I tried searching the forum already and found a thread with this on it:

Dim ans As String
ans = InputBox("Enter a value", "Data Entry")
Range("D" & Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Row + 1).Value = ans

... but it's not copying to sheet 2, and it's overwriting the first reference number that was input. I'd be really grateful for an explanation of what's wrong here too so I can learn from it - I'm brand spanking new to excel and have learned loads in the past week so I'm keen to learn more ;)

Thanks so much xx
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You need to reference sheet2 as below


Code:
Dim ans As String
ans = InputBox("Enter a value", "Data Entry")
[COLOR=#800080][B]Sheets("Sheet2").[/B][/COLOR]Range("D" & Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Row + 1).Value = ans
 
Upvote 0
Thanks so much Ozbod, that works a treat.

So I guess I need to specify the sheet first before I set the range.

I think I might delve a bit deeper into the realms of Visual Basic... I had no idea what it was capable of :cool:
 
Upvote 0
No problems Cazzdevil,

In your case it was setting the range in the active sheet based on the last row in the second sheet and writing the value.

... and I agree, there is so much you can do in VBA that would take you ages to do manually, and normally in a few lines of code once you understand it better.

Well worth exploring
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

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