vba sort range problem

A

ADK

Beginner at vba.
Get error at line: GroupIt = "B3:E" + LastRow

Example of what I am trying to do: say last row is 36 this time around, so
GroupIt would = B3:E36

What code can perform this correctly?


Sub SortGroup()
Dim GroupIt As Range
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
GroupIt = "B3:E" + LastRow
Range(GroupIt).Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' ,
DataOption1:=xlSortNormal

End Sub
 
B

Bob Phillips

GroupIt is a range so you cannot set it to a string. Anyway, you don't need
it

Sub SortGroup()
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
Range("B3:E" + LastRow).Sort Key1:=ActiveCell, _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom ' , _
DataOption1:=xlSortNormal

End Sub





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
A

ADK

I get an error at the Range:)B3...... line

Bob Phillips said:
GroupIt is a range so you cannot set it to a string. Anyway, you don't
need
it

Sub SortGroup()
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
Range("B3:E" + LastRow).Sort Key1:=ActiveCell, _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom ' , _
DataOption1:=xlSortNormal

End Sub





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

ADK said:
Beginner at vba.
Get error at line: GroupIt = "B3:E" + LastRow

Example of what I am trying to do: say last row is 36 this time around,
so
GroupIt would = B3:E36

What code can perform this correctly?


Sub SortGroup()
Dim GroupIt As Range
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
GroupIt = "B3:E" + LastRow
Range(GroupIt).Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' ,
DataOption1:=xlSortNormal

End Sub
 
B

Bob Phillips

Sorry, the + should be & there.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Bob Phillips said:
GroupIt is a range so you cannot set it to a string. Anyway, you don't need
it

Sub SortGroup()
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
Range("B3:E" + LastRow).Sort Key1:=ActiveCell, _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom ' , _
DataOption1:=xlSortNormal

End Sub





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

ADK said:
Beginner at vba.
Get error at line: GroupIt = "B3:E" + LastRow

Example of what I am trying to do: say last row is 36 this time around, so
GroupIt would = B3:E36

What code can perform this correctly?


Sub SortGroup()
Dim GroupIt As Range
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
GroupIt = "B3:E" + LastRow
Range(GroupIt).Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' ,
DataOption1:=xlSortNormal

End Sub
 
A

ADK

thanks!!!

Bob Phillips said:
Sorry, the + should be & there.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Bob Phillips said:
GroupIt is a range so you cannot set it to a string. Anyway, you don't need
it

Sub SortGroup()
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
Range("B3:E" + LastRow).Sort Key1:=ActiveCell, _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom ' , _
DataOption1:=xlSortNormal

End Sub





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

ADK said:
Beginner at vba.
Get error at line: GroupIt = "B3:E" + LastRow

Example of what I am trying to do: say last row is 36 this time around, so
GroupIt would = B3:E36

What code can perform this correctly?


Sub SortGroup()
Dim GroupIt As Range
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'MsgBox LastRow
End If
GroupIt = "B3:E" + LastRow
Range(GroupIt).Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' ,
DataOption1:=xlSortNormal

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top