Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
plh plh is offline
external usenet poster
 
Posts: 48
Default Programed sort generates error: originated as recorded macro

Hello Excel Gurus,
I have the function command to perform a sort:
Private Function SortRows()
Dim i As Integer
i = 1
With Worksheets("Sheet2")
For i = 1 To 20
Debug.Print .Range("A" & i).Value
If IsEmpty(.Range("A" & i).Value) = True Then
Do While IsEmpty(.Range("A" & i).Value) = True
.Rows(i & ":" & i).Delete Shift:=xlUp
Loop
.Range("A20").Value = "END"
End If
Next i
i = 1
Do While .Range("A" & i).Value < "END"
i = i + 1
Loop
i = i
.Range("A1:J" & i - 1).Select
..Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending
End With
End Function

When it hits the line

..Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending

I get the error #1004:
"The sort reference is not valid. Make sure it's within the data you want to
sort, and the first Sort By box isn't the same or blank."

The command is a simplified version of a recorded macro that generated the same
error. I think the problem may have to do with the fact that I have been
deleting rows prior the issuance of the command. Is that correct? If so how do I
fix it?
Thank You,
-plh


--
Where are we going and why am I in this HAND BASKET??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Programed sort generates error: originated as recorded macro

You qualified lots of your ranges, but missed them in this line:

.Range("A1:J" & i - 1).Sort _
Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order2:=xlAscending

.Range("A1:J" & i - 1).Sort _
Key1:=.Range("A1"), Order1:=xlAscending, _
Key2:=.Range("B1"), Order2:=xlAscending

(those dots in the key# parms are important)

plh wrote:

Hello Excel Gurus,
I have the function command to perform a sort:
Private Function SortRows()
Dim i As Integer
i = 1
With Worksheets("Sheet2")
For i = 1 To 20
Debug.Print .Range("A" & i).Value
If IsEmpty(.Range("A" & i).Value) = True Then
Do While IsEmpty(.Range("A" & i).Value) = True
.Rows(i & ":" & i).Delete Shift:=xlUp
Loop
.Range("A20").Value = "END"
End If
Next i
i = 1
Do While .Range("A" & i).Value < "END"
i = i + 1
Loop
i = i
.Range("A1:J" & i - 1).Select
.Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending
End With
End Function

When it hits the line

.Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending

I get the error #1004:
"The sort reference is not valid. Make sure it's within the data you want to
sort, and the first Sort By box isn't the same or blank."

The command is a simplified version of a recorded macro that generated the same
error. I think the problem may have to do with the fact that I have been
deleting rows prior the issuance of the command. Is that correct? If so how do I
fix it?
Thank You,
-plh

--
Where are we going and why am I in this HAND BASKET??


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
plh plh is offline
external usenet poster
 
Posts: 48
Default Programed sort generates error: originated as recorded macro

Works swimmingly now, thank you!
-plh

In article , Dave Peterson says...

You qualified lots of your ranges, but missed them in this line:

.Range("A1:J" & i - 1).Sort _
Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order2:=xlAscending

.Range("A1:J" & i - 1).Sort _
Key1:=.Range("A1"), Order1:=xlAscending, _
Key2:=.Range("B1"), Order2:=xlAscending

(those dots in the key# parms are important)

plh wrote:

Hello Excel Gurus,
I have the function command to perform a sort:
Private Function SortRows()
Dim i As Integer
i = 1
With Worksheets("Sheet2")
For i = 1 To 20
Debug.Print .Range("A" & i).Value
If IsEmpty(.Range("A" & i).Value) = True Then
Do While IsEmpty(.Range("A" & i).Value) = True
.Rows(i & ":" & i).Delete Shift:=xlUp
Loop
.Range("A20").Value = "END"
End If
Next i
i = 1
Do While .Range("A" & i).Value < "END"
i = i + 1
Loop
i = i
.Range("A1:J" & i - 1).Select
.Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending
End With
End Function

When it hits the line

.Range("A1:J" & i - 1).Sort Key1:=Range("A1"), Order1:=xlAscending,
Key2:=Range("B1"), Order2:=xlAscending

I get the error #1004:
"The sort reference is not valid. Make sure it's within the data you want to
sort, and the first Sort By box isn't the same or blank."

The command is a simplified version of a recorded macro that generated the same
error. I think the problem may have to do with the fact that I have been
deleting rows prior the issuance of the command. Is that correct? If so how do I
fix it?
Thank You,
-plh

--
Where are we going and why am I in this HAND BASKET??




--
Where are we going and why am I in this HAND BASKET??
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
2003 macro generates compiler error on 2007 KenInPortland Excel Worksheet Functions 2 September 2nd 08 09:45 PM
VB Code generates error on another machine? Richard Smolik (Kordia) Excel Programming 4 August 9th 07 07:48 AM
Working application - Now generates error Madiya Excel Programming 4 May 24th 05 12:18 PM
Recorded Macro to Set page breaks generates error. Jared Excel Programming 13 December 9th 04 06:45 AM
Find generates error message James Houston Excel Programming 3 April 28th 04 07:55 AM


All times are GMT +1. The time now is 08:37 AM.

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"