Help constructing a Sort Macro

SSJSatch

New Member
Joined
Sep 27, 2006
Messages
4
I have been working on a new Macro to sort a large spreadsheet.

I have a spreadsheet and would like to sort it, however the sorting range is defined by variables. How do I incorporate these variables into the range properly.

Here is my code so far, can someone please offer some advice?

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/27/2006 by sb32013t
'

Dim sortProj As String
Dim rangebeg As Integer
Dim rangeend As Integer


rangebeg = 1
'Prompts user for a project to sort
sortProj = Application.InputBox("Enter the name of the Project to sort please")
'Exits if Cancel is hit
If sortProj = "False" Then Exit Sub
'Selects the cell to start sorting
Do While ActiveCell <> sortProj
ActiveCell.Select
ActiveCell.Offset(1, 0).Select
rangebeg = rangebeg + 1
Loop

'Finds the end of the range
Do While ActiveCell = sortProj
rangeend = rangeend + 1
Loop
'Sorts the Data
Range(rangebeg : rangebeg , rangened : rangeend).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal


End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,143,637
Messages
5,719,966
Members
422,251
Latest member
bonebreaker100

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
Top