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
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