Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default I thought this was ordinary sorting...

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default I thought this was ordinary sorting...

Correction; The sort key1 argument is C1, not C3 - not that it matters...

"kkarre" wrote:

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default I thought this was ordinary sorting...

This worked for me with the data you posted:

Sub AAA()
Dim lastrow As Long
lastrow = Cells(Rows.Count, _
"A").End(xlUp).Row
Range("A1:W" & lastrow).Sort _
Key1:=Range("C3"), _
Order1:=xlDescending, _
header:=xlNo
End Sub


If you actually have a header row you don't want sorted, then change to

header:=xlYes
--
Regards,
Tom Ogilvy


"kkarre" wrote:

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default I thought this was ordinary sorting...

Hello Tom,
Thanks for swift response!
I failed to mention I'm working in VSTO 2005 SE, trying to do this from
VB.NET...
I get it to work with VBA, but VB.NET will not eventhough I change all
constans to the .NET counterparts.
Have You used VSTO?
/TiA, kk

"Tom Ogilvy" wrote:

This worked for me with the data you posted:

Sub AAA()
Dim lastrow As Long
lastrow = Cells(Rows.Count, _
"A").End(xlUp).Row
Range("A1:W" & lastrow).Sort _
Key1:=Range("C3"), _
Order1:=xlDescending, _
header:=xlNo
End Sub


If you actually have a header row you don't want sorted, then change to

header:=xlYes
--
Regards,
Tom Ogilvy


"kkarre" wrote:

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default I thought this was ordinary sorting...

No, I haven't.

--
Regards,
Tom Ogilvy


"kkarre" wrote:

Hello Tom,
Thanks for swift response!
I failed to mention I'm working in VSTO 2005 SE, trying to do this from
VB.NET...
I get it to work with VBA, but VB.NET will not eventhough I change all
constans to the .NET counterparts.
Have You used VSTO?
/TiA, kk

"Tom Ogilvy" wrote:

This worked for me with the data you posted:

Sub AAA()
Dim lastrow As Long
lastrow = Cells(Rows.Count, _
"A").End(xlUp).Row
Range("A1:W" & lastrow).Sort _
Key1:=Range("C3"), _
Order1:=xlDescending, _
header:=xlNo
End Sub


If you actually have a header row you don't want sorted, then change to

header:=xlYes
--
Regards,
Tom Ogilvy


"kkarre" wrote:

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default I thought this was ordinary sorting...

Here's another example of my code (in a VSTO 2005 workbook):
Private Sub ThisWorkbook_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
Try
Dim Bl As Excel.Worksheet = CType(Me.ActiveSheet, Excel.Worksheet)
Bl.Range("A1:D6").Select()
Dim x As Object = Bl.Range("A1:D6").Sort(Key1:=Bl.Cells(1, 3))
MessageBox.Show(x.ToString)
Catch ex As Exception

Finally
Me.Save()
End Try
End Sub

The messagebox


"kkarre" wrote:

Hello all,
I'm trying to sort a range on a column containing some empty cells (to get
them last
and later get rid of these rows)

Sheet like this:

Header1 Header2 Header3 Header4 etc.
1 qw xxx
2 qw 123456 yyy
3 qw 234567 zzz
4 er aaa
5 er 345678 bbb

Range("A1:W" & LastRow).Sort(Range("C3"))
doesn't seem to do the trick.
Sometimes nothing happens, sometimes it sorts the columns although
sorting rows is default!
Any code that DOES sort a range's rows on the third column would be greatly
appreciated!
/kk

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
harder than i thought Tomkat743 Excel Discussion (Misc queries) 2 March 9th 09 02:37 PM
Don't think it's possible, but I thought I would ask. smaumau Excel Worksheet Functions 1 April 3rd 06 11:20 PM
This is A LOT harder than I thought it would be Robert Excel Discussion (Misc queries) 13 August 24th 05 12:20 AM
On second thought ... Jerry Kinder New Users to Excel 0 November 26th 04 02:38 AM
out of the ordinary question JohnE Excel Programming 3 March 5th 04 08:34 AM


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