Macro to sort data in a list.

SnowBalls

New Member
Joined
Jun 19, 2009
Messages
2
Hi
I have a list with data in it and I need a macro to sort the data, but here is the tricky part, I am always adding and deleting rows, so I need the "range" in the macro to also grow and shrink. Any help will be greatly appriciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I wrote this code for the same problem but it doesnt seem to work though cant work out why - any ideas?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Dynamic range is Consultants, sheet is Basis, start of Consultants d.range is G5
Dim r As Range
  
  Set r = Intersect(Target, Range("Consultants"))
   If r Is Nothing Or Target.Count > 1 Then Exit Sub
  
 
'This bit sorts first column
With Sheets("Basis")
    .Range("Consultants").Sort Key1:=.Range("g5"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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