Excel VBA Sort Multiple Tabs (not all tabs)

jrlop

New Member
Joined
Jul 27, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi guys,
I have an excel file with many tabs. For the most part my data goes from column A5 - H150. I am wanting to sort some tabs (smallest to largest) by column C, some tabs by column E and other tabs by column H. I have the tabs grouped those that need to be sorted by column C, followed by column E and then H sort tabs. I know very little about VBA but this one is pretty advanced for me. I am hoping to be able to create three different Macros (one that sorts column C, column E and Column H) and run each separately. I really do not want to have to sort this manually and I have to create this same report for a total of 4 teams. I greatly appreciate your help. Jorge
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You're best off recording a macro of you data sorting the tabs/columns you want. Other than that, you'll need to provide the names of the sheets and which columns within those sheets you want to data sort.
 
Upvote 0
You're best off recording a macro of you data sorting the tabs/columns you want. Other than that, you'll need to provide the names of the sheets and which columns within those sheets you want to data sort.
Ok thanks for the feedback. I was hoping I could automate this.
 
Upvote 0
Can you provide the sheet names that you want to sort for Column C, E & H
 
Upvote 0
Can you provide the sheet names that you want to sort for Column C, E & H

Ok below are the sheet names I have so far and which column needs to be sorted for the sheet. Once I see how the Macro is written, I can add more any other sheets. The data that needs to be sorted for each sheet starts on A6 and goes through row 200. Tabs that sort on column C go A6 : C200; for column E go A6 : E200 and same for H A6 : H200. I hope this helps. Thank you so much.

P&L PerformanceSorted by
Clinical KPIs
Clinical KPI OBHG DelColumn H
Clinical KPI OBHG Del %Column H
Clinical KPI OSA DelColumn H
Clinical KPI OSA Del %Column H
Clinical KPI NTSVColumn H
Clinical KPI OBED-Triage VolColumn H
Clinical KPI wRVUsColumn H
Mozart Reports
P&L_QoPYQ (ALL)
P&L_QoPYQ (SS)
P&L_YoY (ALL)
P&L_YoY (SS)
Churned Programs (SS)
P&L_YoY (ALL) YE F & B
P&L_YoY (SS) YE F & B
P&L_CQ Bud Var TCRColumn C
P&L_CQ Bud Var ORDColumn C
P&L_CQ Bud Var PSRColumn C
P&L_CQ Bud Var TRColumn C
P&L_CQ Bud Var MMColumn C
P&L_CQ Bud Var TCSColumn C
P&L_CQ Bud Var TCoSColumn C
P&L_CQ Bud Var GPColumn C
P&L_CY Bud Var TCRColumn C
P&L_CY Bud Var ORDColumn C
P&L_CY Bud Var PSRColumn C
P&L_CY Bud Var TRColumn C
P&L_CY Bud Var MMColumn C
P&L_CY Bud Var TCSColumn C
P&L_CY Bud Var TCoSColumn C
P&L_CY Bud Var GPColumn C
P&L_CQ Bud Var TCR (SS)Column C
P&L_CQ Bud Var ORD (SS)Column C
P&L_CQ Bud Var PSR (SS)Column C
P&L_CQ Bud Var TR (SS)Column C
P&L_CQ Bud Var MM (SS)Column C
P&L_CQ Bud Var TCS (SS)Column C
P&L_CQ Bud Var TCoS (SS)Column C
P&L_CQ Bud Var GP (SS)Column C
P&L_CQ Bud Var GP excl MM (SS)Column C
P&L_CY Bud Var TCR (SS)Column C
P&L_CY Bud Var ORD (SS)Column C
P&L_CY Bud Var PSR (SS)Column C
P&L_CY Bud Var TR (SS)Column C
P&L_CY Bud Var MM (SS)Column C
P&L_CY Bud Var TCS (SS)Column C
P&L_CY Bud Var TCoS (SS)Column C
P&L_CY Bud Var GP (SS)Column C
P&L_CY Bud Var GP excl MM (SS)Column C
P&L_YE FB Var TCRColumn C
P&L_YE FB Var ORDColumn C
P&L_YE FB Var PSRColumn C
P&L_YE FB Var TRColumn C
P&L_YE FB Var MMColumn C
P&L_YE FB Var TCSColumn C
P&L_YE FB Var TCoSColumn C
P&L_YE FB Var GPColumn C
P&L_YE FB Var TCR (SS)Column C
P&L_YE FB Var ORD (SS)Column C
P&L_YE FB Var PSR (SS)Column C
P&L_YE FB Var TR (SS)Column C
P&L_YE FB Var MM (SS)Column C
P&L_YE FB Var TCS (SS)Column C
P&L_YE FB Var TCoS (SS)Column C
P&L_YE FB Var GP (SS)Column C
P&L_YE FB Var GP excl MM (SS)Column C
P&L_CQoPYQ Act Var TCRColumn E
P&L_CQoPYQ Act Var ORDColumn E
P&L_CQoPYQ Act Var PSRColumn E
P&L_CQoPYQ Act Var TRColumn E
P&L_CQoPYQ Act Var MMColumn E
P&L_CQoPYQ Act Var TCSColumn E
P&L_CQoPYQ Act Var TCoSColumn E
P&L_CQoPYQ Act Var GPColumn E
P&L_YOY Act Var TCRColumn E
P&L_YOY Act Var ORDColumn E
P&L_YOY Act Var PSRColumn E
P&L_YOY Act Var TRColumn E
P&L_YOY Act Var MMColumn E
P&L_YOY Act Var TCSColumn E
P&L_YOY Act Var TCoSColumn E
P&L_YOY Act Var GPColumn E
P&L_CQoPYQ Act Var TCR (SS)Column E
P&L_CQoPYQ Act Var ORD (SS)Column E
P&L_CQoPYQ Act Var PSR (SS)Column E
P&L_CQoPYQ Act Var TR (SS)Column E
P&L_CQoPYQ Act Var MM (SS)Column E
P&L_CQoPYQ Act Var TCS (SS)Column E
P&L_CQoPYQ Act Var TCoS (SS)Column E
P&L_CQoPYQ Act Var GP (SS)Column E
P&L_CQoPYQ Act Var GP exMM (SS)Column E
P&L_YOY Act Var TCR (SS)Column E
P&L_YOY Act Var ORD (SS)Column E
P&L_YOY Act Var PSR (SS)Column E
P&L_YOY Act Var TR (SS)Column E
P&L_YOY Act Var MM (SS)Column E
P&L_YOY Act Var TCS (SS)Column E
P&L_YOY Act Var TCoS (SS)Column E
P&L_YOY Act Var GP (SS)Column E
P&L_YOY Act Var GP excl MM (SS)Column E
 
Upvote 0
This code should get you started, it will data sort sheet Clinical KPI OBHG Del by column H.

Code:
Worksheets("Clinical KPI OBHG Del").Activate
Range("A5:H150").Sort Key1:=Range("H1"), Order1:=xlAscending, Header:=xlYes
 
Upvote 0
Do you need separate macros, or would you be happy with just one macro?
Also Is the list of sheet names & the column to be sorted by in a sheet within that workbook?
 
Upvote 0
Do you need separate macros, or would you be happy with just one macro?
Also Is the list of sheet names & the column to be sorted by in a sheet within that workbook?

If it can be done all in one macro, that would be wonderful but I am not done building out the data sheets- will it be easy to update. Yes I have the sheets listed in the very first tab in the file- tab name is "KutoolsforExcel" Column A is the tab name and column B is the column I want to sort the sheet by. Not all tabs need to be sorted. Man this would be some great magic if you can pull this off :) I love excel but this is higher power excel! LOL I appreciate everyone's help!! Let me know if you need anything else.
 
Upvote 0
If it can be done all in one macro, that would be wonderful but I am not done building out the data sheets- will it be easy to update. Yes I have the sheets listed in the very first tab in the file- tab name is "KutoolsforExcel" Column A is the tab name and column B is the column I want to sort the sheet by. Not all tabs need to be sorted. Man this would be some great magic if you can pull this off :) I love excel but this is higher power excel! LOL I appreciate everyone's help!! Let me know if you need anything else.

In column B (the sort by column), should I enter "column H" or "H"
Thanks!
 
Upvote 0
Just put the column letter & then you could use
VBA Code:
Sub jrlop()
   Dim Rng As Range, Cl As Range
   
   With Sheets("KutoolsforExcel")
      Set Rng = .Range("A2", .Range("B" & Rows.Count).End(xlUp))
   End With
   For Each Cl In Rng
      If Cl.Offset(, 1) <> "" Then
         With Sheets(Cl.Value)
            .Range("A5:" & Cl.Offset(, 1) & "200").Sort key1:=.Range(Cl.Offset(, 1) & "5"), order1:=xlAscending, Header:=xlYes
         End With
      End If
   Next Cl
End Sub
The sheet names in col A must be an exact match for the actual name of the sheet.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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