Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Sorting, one last time

Embrassed to ask again but I've tried everything. The code is finally working
as is the command button but it's not sorting Column "D" I need it to sort
only Column's A,B,C,D
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp))
Set rng1 = .Cells(3, "A").End(xlToRight)
Set rng = rng.Resize(, rng1.Column)
rng.Sort _
Key1:=.Range("A3"), _
Order1:=xlAscending, _
Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), _
ThisWorkbook.Name & "!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sorting, one last time

If you know it's exactly 4 columns wide, how about:

Set rng = rng.Resize(, 4)

And drop the rng1 stuff completely???

Richard wrote:

Embrassed to ask again but I've tried everything. The code is finally working
as is the command button but it's not sorting Column "D" I need it to sort
only Column's A,B,C,D
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp))
Set rng1 = .Cells(3, "A").End(xlToRight)
Set rng = rng.Resize(, rng1.Column)
rng.Sort _
Key1:=.Range("A3"), _
Order1:=xlAscending, _
Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), _
ThisWorkbook.Name & "!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Sorting, one last time

as dave mentioned, get rid of the rng1. and if you want to sort by column D,
change the key address

Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp)).Resize(, 4)
rng.Select
rng.Sort Key1:=.Range("A3"), Order1:=xlAscending, Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), ThisWorkbook.Name & _
"!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub

--


Gary


"Richard" wrote in message
...
Embrassed to ask again but I've tried everything. The code is finally working
as is the command button but it's not sorting Column "D" I need it to sort
only Column's A,B,C,D
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp))
Set rng1 = .Cells(3, "A").End(xlToRight)
Set rng = rng.Resize(, rng1.Column)
rng.Sort _
Key1:=.Range("A3"), _
Order1:=xlAscending, _
Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), _
ThisWorkbook.Name & "!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 145
Default Sorting, one last time

Have you tried changing
Key1:=.Range("A3"), _

to
Key1:=.Range("D3"), _

"Richard" wrote in message
...
Embrassed to ask again but I've tried everything. The code is finally

working
as is the command button but it's not sorting Column "D" I need it to sort
only Column's A,B,C,D
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp))
Set rng1 = .Cells(3, "A").End(xlToRight)
Set rng = rng.Resize(, rng1.Column)
rng.Sort _
Key1:=.Range("A3"), _
Order1:=xlAscending, _
Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), _
ThisWorkbook.Name & "!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Sorting, one last time

Thanks, that worked!

"Dave Peterson" wrote:

If you know it's exactly 4 columns wide, how about:

Set rng = rng.Resize(, 4)

And drop the rng1 stuff completely???

Richard wrote:

Embrassed to ask again but I've tried everything. The code is finally working
as is the command button but it's not sorting Column "D" I need it to sort
only Column's A,B,C,D
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Sort"
Dim rng As Range, rng1 As Range
With Worksheets("HList")
Set rng = .Range(.Cells(3, "A"), .Cells(Rows.Count, "A").End(xlUp))
Set rng1 = .Cells(3, "A").End(xlToRight)
Set rng = rng.Resize(, rng1.Column)
rng.Sort _
Key1:=.Range("A3"), _
Order1:=xlAscending, _
Header:=xlNo
End With
Application.OnTime Now + TimeSerial(0, 0, 2), _
ThisWorkbook.Name & "!ResetCaption"
CommandButton1.Caption = "Sorting..."
End Sub


--

Dave Peterson

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
Real-time sorting Fernando Ronci Excel Discussion (Misc queries) 11 April 16th 09 09:13 PM
Sorting time formats Mike Excel Discussion (Misc queries) 1 December 10th 07 07:32 PM
Sorting time in Excel forest8 Excel Discussion (Misc queries) 1 June 7th 07 09:12 AM
sorting time format Guerilla Excel Discussion (Misc queries) 1 March 30th 07 12:56 PM
sorting time in a column mattguerilla Excel Programming 2 May 25th 05 07:43 AM


All times are GMT +1. The time now is 11:30 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"