View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Sorting Rows in VBA

Actually, it is not even a single cell it is nothing real. I read Rows as
Range. Rest still stands though.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bob Phillips" wrote in message
...
You are only defining a single cell to sort (a bit pointless no?).

You might mean all rows between the first and last
.Rows(intFirstRow & ":" & intSecondRow).Sort

or perhaps you mean only some columns, say H:M, in which case use
.Range(.Cells(intFirstRow,"H"),.Cells(intSecondRow ,"M")).Sort

And then you haven't specified the key to sort on, which should be the

first
data cell in a specific column.

BTW, Dim intFirstRow, intSecondRow as Integer doesn't declare both

variables
as Integer, the first is a variant. You have to be specific

Dim intFirstRow as Integer, intSecondRow as Integer

--

HTH



RP
(remove nothere from the email address if mailing direct)


"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