View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Sorting Rows in VBA

Sub AA()
Dim intFirstRow as Long, intSecondRow as Long
intFirstRow = 5
intSecondrow = 9
With ActiveSheet
.Range(intFirstRow & ":" & intSecondrow).Sort _
key1:=.Cells(intFirstRow, 1)
End With
End Sub

Worked for me
--
Regards,
Tom Ogilvy

"Kevin" wrote in message
...
OK. I've got a feeling that I'm going to feel like an idiot when someone
tells me what I'm doing wrong, but I am having trouble sorting rows in

VBA.
Consider the following code snippet:

Dim intFirstRow, intSecondRow as Integer
intFirstRow = 9
intSecondRow = 15
With ActiveSheet
.Rows(intFirstRow, intSecondRow).Sort
End With

I keep getting run-time error 1004 which says "Application-defined or
object-defined error", which seems to mean: Something is wrong. VBA's not
sure what it is, but something is definitely wrong.

Alternatively, I tried the line:
.Rows(.Rows(intFirstRow),.Rows(intSecondRow)).Sort

I got the same error.

Can anyone point me in the right direction?

Thanks in advance!!!

--
Kevin