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
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Watch MrExcel Video

Forum statistics

Threads
1,109,436
Messages
5,528,749
Members
409,834
Latest member
vexceled

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top