Excel VBA Loop to create column header variables

hellfire45

Active Member
Joined
Jun 7, 2014
Messages
464
Hi guys,

Has anybody ever written a loop that will make an INTEGER variable out of each column header in a worksheet? If so, could you please share the method?

thank you!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You can't create variables 'on the fly' like that in VBA, what are you actually trying to do?
 
Upvote 0
HI guys,

I am having the same issue, so please forgive me for rail-roading the thread. My requirement is to create a macro to historically list and group data by year for a variable number of years. The number of years is not known and may expand or shrink as required. Currently, if there are 4 years of data - the headings will be FY18, FY17, FY16, FY15, and the data belonging to each of these years will be listed below. However, next year, the same data will be required along with the new FY, so the headings will be FY19, FY18, FY17, FY16, FY15, and so on for up to 20 years or 25, for corporate modelling.

I was wondering if "Dim FY_nn As String" can be contained within a loop, where the nn is replaced by a number for the number of each year required.

Any suggestions will be so welcome, as I am completely at a loss how I can achieve this

Nanette
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,619
Members
452,661
Latest member
Nonhle

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