Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default Sorting Rows in VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sorting Rows in VBA

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting out rows Tom Excel Worksheet Functions 2 June 9th 08 08:43 PM
Sorting rows into a row Sunnyskies Excel Discussion (Misc queries) 1 February 7th 08 12:00 AM
Sorting Rows Quick Orange Excel Worksheet Functions 1 August 6th 06 03:55 PM
Sorting rows Mario Excel Worksheet Functions 3 July 13th 06 06:51 PM
[sorting rows] digisummo Excel Worksheet Functions 1 June 16th 06 03:45 PM


All times are GMT +1. The time now is 06:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"