VBA populate list using user input range

dmurphy1991

New Member
Joined
Jan 10, 2014
Messages
22
So, i'm new to using VBA but have managed to get a few things done through online help etc.

but i'm now trying to build my own macro instead of editing and adding to an existing example.

basically i'm tryign to create a hypothetical summary of a company's stores' sales for the day. I want the user to be able to specify the number of stores that were open, and then from A2 down, populate A with 'Store' & Number up to the user enetered value.

I.e. user enters 4 stores:
A B C

Store 1
Store 2
Store 3
Store 4


The ultimate goal is to allow the user to set all parameters including budgets (something i have done using an existing example), number of stores open and to be able to enter any reason for falling outside of budgets (also covered from existing example). and the user to be able to chose to lookup the sales value for each store (based on a raw sales sheet which would hypothetically be compiled from each store sending a report) or to chose to manually enter rach store's sales figures for the day.

Any help would be greatly appreciated.

Thanks

Dave
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I am just typing this up in this window so the code won't be tested, but it should be relatively straight-forward.

Code:
Sub ListStores()
     StoreCount = InputBox("Enter the number of stores open today:")
     If StoreCount = "" Then Exit Sub 'user cancelled
     For i = 1 to StoreCount
          Range("A"&i+1).Value = "Store " & i
     Next i
End Sub
 
Upvote 0
Excellent thanks very much, i had seen the use of 'i' before but didn't really understand how to use it, this helps though thanks! i'll have a play around with it too

Dave
 
Upvote 0
There is no magic to 'i' you could just as easily use For myCount = 1 to StoreCount...Next myCount

For more information about using For Next loops, you can google VBA For Next Loop

That being said, 'i' is the standard convention for For Next loops.
 
Upvote 0
Maybe i'm confusing myself then, i didn't uite understand how it knew when is meant by i, how it knows that i is refering to the row number in column A. Trying to add a line in now that will delete all previous stores when entering new ones. hopefully i can get this on my own now!
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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