Link to home
Start Free TrialLog in
Avatar of indigo6
indigo6

asked on

VB Macro to Sort Columns in multiple workbooks

Hello,
I have an excel workbook with about 48 sheets. About 40 of those sheets are formatted the same way, and I need to sort from C2 to the end, E2 to the end, and G2 to the end. I have tried recording a macro, but it only works for one sheet, and it's hard to adapt because each sheet has a range of different length. After the sort, I then need to hide columns A,B,H,L, and M. Thanks for all the help!
Avatar of Faustulus
Faustulus
Flag of Singapore image

Are the columns in any one sheet all of the same length? If not, can you tell which is the longest column?
Avatar of Patrick Matthews
A sample file would be helpful
Avatar of indigo6
indigo6

ASKER

The column lengths always vary. The longest column is 1319 rows long.
The column lengths always vary.

That's not a worry at all.  However...

I have an excel workbook with about 48 sheets. About 40 of those sheets are formatted the same way, ...

Which have to be sorted?  All worksheets?  Only the ~40 or so?  If all, then what sorting instructions should be used for the ~8 or so that are different?

...and I need to sort from C2 to the end, E2 to the end, and G2 to the end.

What columns on the worksheets are actually populated?  Are there header rows, or not?

This is why I asked for a sample file :)
Avatar of indigo6

ASKER

Let me see if I can make a sample file. It's private data, so I'm a bit leery about it.

Also, I can move the sheets that don't need to be sorted to another workbook, so let's go on the assumption that all sheets need to be sorted.

Yes, there are header rows. Columns A-O have data.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indigo6

ASKER

This is perfect! Nice separation of statements to make it easy to edit for future use too!