tonywatsonhelp
Well-known Member
- Joined
- Feb 24, 2014
- Messages
- 3,210
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi Everyone,
OK I hope this is clear I know what i want to do so lets see,
I have been looking for a way I can declare the columns my headers are in then use then in any macro instead of always saying "Column D" for example,
I find I end up editing a lot of my macros because i make changes and those changes change the location of a cell or column
So here's what i was thinking.
Please help if this is possible as i have no idea how it could be done but have seen others do similar over the years
I want to some how set it up the my macro finds and stores where my headers for each page are.
I realise we sometimes us the same headers in different sheets but i assume we record the sheet as well as the header name.
So I want something like this,
A place in the VBA editor where I can store columns and cells as names?
For example
Lets say I have a header called "Name" in sheet "Data"
I'd like a macro that goes to Sheet"Data" row 1 and finds the name "Name" , then stores whatever column letter that is (Must be the letter)
If this was written in English it would read like this.
So if "Name Was in Column D"
it would read as
DatNME = the Column letter of: find "Name" in Sheet"Data" row 1,
The when i write a macro in that document Instead of saying Range("A2:A" & lastrow) i could put Range(DatNME & "2:" & DatNME & lastrow) and it would know it was "D"
any ideas help would be greatly apreasiated,
Thanks
Tony
OK I hope this is clear I know what i want to do so lets see,
I have been looking for a way I can declare the columns my headers are in then use then in any macro instead of always saying "Column D" for example,
I find I end up editing a lot of my macros because i make changes and those changes change the location of a cell or column
So here's what i was thinking.
Please help if this is possible as i have no idea how it could be done but have seen others do similar over the years
I want to some how set it up the my macro finds and stores where my headers for each page are.
I realise we sometimes us the same headers in different sheets but i assume we record the sheet as well as the header name.
So I want something like this,
A place in the VBA editor where I can store columns and cells as names?
For example
Lets say I have a header called "Name" in sheet "Data"
I'd like a macro that goes to Sheet"Data" row 1 and finds the name "Name" , then stores whatever column letter that is (Must be the letter)
If this was written in English it would read like this.
So if "Name Was in Column D"
it would read as
DatNME = the Column letter of: find "Name" in Sheet"Data" row 1,
The when i write a macro in that document Instead of saying Range("A2:A" & lastrow) i could put Range(DatNME & "2:" & DatNME & lastrow) and it would know it was "D"
any ideas help would be greatly apreasiated,
Thanks
Tony