How to resort data automatically

excelnovice_1

New Member
Joined
Nov 2, 2016
Messages
3
I have 3 sheets of data.

Sheet A: Has a drop down list with statistics (checks, sales, items) which drives the data on sheet C (see below). There is also a graph on this sheet that is based on the data on sheet C (see below).

Sheet B: Has all of the raw data that the workbook is based on.

Sheet C: Has a list of data that pulls from Sheet B depending on what is selected from the drop down list on Sheet A. For example, if I select 'checks' from the dropdown list on Sheet A, this list on Sheet C will show the number of checks that each employee has registered. This list of data drives the graph on sheet A.

What I am trying to do is to get the list of data on sheet C to automatically sort from least to greatest everytime I update the selection from the drop down list on sheet A. Some employees have higher checks than others, more revenue, etc. So when I change the statistic its not always in order and the graph has random highs and low points instead or constantly increasing.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
excelnovice_1,
Welcome to to the Forum.
So when the selection from the drop down on Sheet A changes...You want to automatically sort column/columns on sheet C.
So assuming the cell that has the drop down on Sheet A is cell C2, and the table of values to be sorted on Sheet C are in columns A, B, and C, and you want them sorted on column C from low to high.
A Worksheet_Change Event on Sheet A should do that. Change the sheet names and columns to match your data. Open your workbook, then open the Visual Basic Editor by right clicking the Sheet A tab, then select 'View Code', then in the selection bar above the large window that say 'General', select 'Worksheet', then paste the code below right over the auto entered 2 lines. Close the Visual basic Editor and save the workbook as macro enabled. Make a copy of this workbook to test the macro on so you don't lose any data.

Depending on which version of Excel you have you may have to enable macros before this will work. Now when you select an item from the drop down in cell C2 on Sheet A, the data on Sheet C columns A, B, and C will be sorted from low to high based on column C values.
Perpa

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim keyRange As Range
Dim LstRw As Integer

Set keyRange = Range("C2")
If Not Intersect(keyRange, Target) Is Nothing Then
    Sheets("Sheet C").Activate
    LstRw = Cells(Rows.Count, "C").End(xlUp).Row
    
    ActiveWorkbook.Worksheets("Sheet C").Sort.SortFields.Clear 
    ActiveWorkbook.Worksheets("Sheet C").Sort.SortFields.Add Key:=Range("C1:C" & LstRw), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 
    With ActiveWorkbook.Worksheets("Sheet C").Sort 
        .SetRange Range("A1:C" & LstRw) 
        .Header = xlGuess 
        .MatchCase = False 
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin 
        .Apply 
    End With 
End if
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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