upobDaPlaya
asked on
Change Position of Column and Column Name
I have an Excel spreadsheet that I receive and each time I receive the file I am forced to place the columns in a different position and also rename the column headers. Within Excel VBA how can I change the column header names and the column position. See tab names called Original and Modified.
EE-ColPosColName.xlsx
EE-ColPosColName.xlsx
Nothing attached.
ASKER
Sorry..have attached now
Is it only those 3 columns? Will there ever be more columns of data? Are they always in the order showing in the "Original" sheet?
Click the button (or run the macro in Module1)
With my code it doesn't matter how many columns there are, what they are called, or what order they are in.
29087143.xlsm
With my code it doesn't matter how many columns there are, what they are called, or what order they are in.
29087143.xlsm
Looks like we'll still need the answers to my questions above as Martin's code doesn't produce the desired output.
You're right. I thought the columns just needed to be reversed.
ASKER
There will always be more than 3 columns but they will always be in the same order for the Original tab. I only used 3 as an example.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Matin, this is awesome ! Can you explain to me the .UsedRange.Columns.Count - How is UsedRange defined ? Does it go to the first column and then go right to determine how many used columns I have ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please don't forget to close this question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx
ASKER
Learned a lot..the various approaches gave me something to think about (had not considered an array) but I implemented Martins as it best fit my problem. Will fool around with the array though..
I’m glad I was able to help.
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
ASKER
Thank you..I will take a look...I am trying to soak up as much VBA as I can so it appears your articles will be a good resource.