Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Select and then sort a list

I have a list with a fixed no. of columns and a variable no. of rows. I need
to sort this list using a button on another sheet. I am not sure if the
error is in selecting the range or in my sort code. The code I have so far is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Select and then sort a list

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows. I
need
to sort this list using a button on another sheet. I am not sure if the
error is in selecting the range or in my sort code. The code I have so far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Select and then sort a list

I've changed all this items, and i've also tried putting it all into With
statements, but it still won't sort the data. It appears that it does not
like my range, possibly!

The new code i'm trying is:

With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells(xlCellTypeLastCell)
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Sheets("Existing").Range("A1"),
Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

"Sharad Naik" wrote:

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows. I
need
to sort this list using a button on another sheet. I am not sure if the
error is in selecting the range or in my sort code. The code I have so far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Select and then sort a list

OK I hadn't read your post fully because of the earlier errors I observed.
Now what range are you trying to set exactly?
Seems you are you trying to set the range to all the used cells in the
worksheet?
If yes then
Change the Set statement as under:
Set rgLastEx = .UsedRange

'(note there is a dot before U)

Else let me know what range you want to sort. It doesn't seem to be only
column A
because of [b11] in the Do statement.

Sharad

"Ian_Limbo" wrote in message
...
I've changed all this items, and i've also tried putting it all into With
statements, but it still won't sort the data. It appears that it does not
like my range, possibly!

The new code i'm trying is:

With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells(xlCellTypeLastCell)
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Sheets("Existing").Range("A1"),
Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

"Sharad Naik" wrote:

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows. I
need
to sort this list using a button on another sheet. I am not sure if
the
error is in selecting the range or in my sort code. The code I have so
far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please
continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select and then sort a list

Your only sorting one cell.
Dim lastRow as long

With Sheets("Existing")
lastRow = .cells(rows.count,1).End(xlup).Row
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix", _
Buttons:=vbExclamation
.Range(.Range("A1"),.Range("A" & lastRow).Sort _
Key1:=.Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

--
Regards,
Tom Ogilvy


"Ian_Limbo" wrote in message
...
I've changed all this items, and i've also tried putting it all into With
statements, but it still won't sort the data. It appears that it does not
like my range, possibly!

The new code i'm trying is:

With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells(xlCellTypeLastCell)
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Sheets("Existing").Range("A1"),
Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

"Sharad Naik" wrote:

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows.

I
need
to sort this list using a button on another sheet. I am not sure if

the
error is in selecting the range or in my sort code. The code I have so

far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort

fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please

continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select and then sort a list

sorry, didn't read your first posting.

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = .Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix", _
Buttons:=vbExclamation
With Sheets("Existing")
.Range("A1").currentRegion..Sort _
Key1:=.Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess
End With
MsgBox prompt:="Existing Sorted"
Else
' This will never be shown.
MsgBox prompt:="No errors have been detected, please continue", _
Buttons:=vbInformation
End If
Loop
End Sub

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Your only sorting one cell.
Dim lastRow as long

With Sheets("Existing")
lastRow = .cells(rows.count,1).End(xlup).Row
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",

_
Buttons:=vbExclamation
.Range(.Range("A1"),.Range("A" & lastRow).Sort _
Key1:=.Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

--
Regards,
Tom Ogilvy


"Ian_Limbo" wrote in message
...
I've changed all this items, and i've also tried putting it all into

With
statements, but it still won't sort the data. It appears that it does

not
like my range, possibly!

The new code i'm trying is:

With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells(xlCellTypeLastCell)
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Sheets("Existing").Range("A1"),
Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

"Sharad Naik" wrote:

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows.

I
need
to sort this list using a button on another sheet. I am not sure if

the
error is in selecting the range or in my sort code. The code I have

so
far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort

fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please

continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Select and then sort a list

I've put the code in but it still bugs out on the sort line, with this error:

1004
The sort ref is not valid. Make sure that its within the data you want to
sort, and the first sort box isn't the same or blank.

If i manually type in the data range as:
set rgLastEx = Range("A1:R37775")
and the sort line as:
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess
then it will sort the data

I have tried Sharad's fix as well with the same problem.

any ideas?

"Tom Ogilvy" wrote:

sorry, didn't read your first posting.

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = .Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort fix", _
Buttons:=vbExclamation
With Sheets("Existing")
.Range("A1").currentRegion..Sort _
Key1:=.Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess
End With
MsgBox prompt:="Existing Sorted"
Else
' This will never be shown.
MsgBox prompt:="No errors have been detected, please continue", _
Buttons:=vbInformation
End If
Loop
End Sub

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Your only sorting one cell.
Dim lastRow as long

With Sheets("Existing")
lastRow = .cells(rows.count,1).End(xlup).Row
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",

_
Buttons:=vbExclamation
.Range(.Range("A1"),.Range("A" & lastRow).Sort _
Key1:=.Range("A1"), _
Order1:=xlAscending, _
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

--
Regards,
Tom Ogilvy


"Ian_Limbo" wrote in message
...
I've changed all this items, and i've also tried putting it all into

With
statements, but it still won't sort the data. It appears that it does

not
like my range, possibly!

The new code i'm trying is:

With Sheets("Existing")
Set rgLastEx = .Range("A1").SpecialCells(xlCellTypeLastCell)
MsgBox rgLastEx
MsgBox prompt:="Error detected, click ok to attempt a sort fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Sheets("Existing").Range("A1"),
Order1:=xlAscending, Header:=xlGuess
MsgBox prompt:="Existing Sorted"
End With

"Sharad Naik" wrote:

As an immediate observervation :-
Change all Range("A1") inside between With and End With to
.Range("A1") (a dot before R).

Then for the 3rd Range("A1") which is not within a With para,
decide which sheet it refers to and change it to
Sheets("That-Sheet-Name").Range("A1")

Sharad

"Ian_Limbo" wrote in message
...
I have a list with a fixed no. of columns and a variable no. of rows.

I
need
to sort this list using a button on another sheet. I am not sure if

the
error is in selecting the range or in my sort code. The code I have

so
far
is:

Private Sub CommandButton2_Click()
Do Until [b11] = 0
With Sheets("Existing")
Set rgLastEx = Range("A1").SpecialCells_(xlCellTypeLastCell)
MsgBox rgLastEx
End With
With Sheets("Options")
Set rgLastOp = Range("A1").SpecialCells_(xlCellTypeLastCell)
End With
If [b11] < 0 Then
MsgBox prompt:="Error detected, click ok to attempt a sort

fix",
Buttons:=vbExclamation
rgLastEx.Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess
MsgBox prompt:="Existing Sorted"
Else: MsgBox prompt:="No errors have been detected, please

continue",
Buttons:=vbInformation
End If
Loop
End Sub


Many thanks for any help

Ian








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
Select a list in 1 cell by selecting an item from another list in Jonners Excel Discussion (Misc queries) 2 July 10th 09 10:31 PM
I want sort a list but the sort is unlit on the home tab how do I chetrx Excel Worksheet Functions 3 November 14th 08 11:47 PM
DATA VALIDATION LIST- CAN I SELECT FROM LIST WITHOUT SCROLLING Bellyjean Excel Worksheet Functions 1 March 7th 08 09:46 PM
how to randomly select a name in a list and then the select the ne [email protected] Excel Worksheet Functions 1 September 20th 06 08:09 AM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM


All times are GMT +1. The time now is 10:29 AM.

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

About Us

"It's about Microsoft Excel"