LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default code for sorting

Thanks a lot Dave, especially for your explanation.

Jack.

"Dave Peterson" schreef in bericht
...
No speed difference as far as I know.

But the difference would be how you defined the range.

If you included the header row (20), then you'd use this line:
Set myRng = .Range("a20:p40")
and use xlyes in the .sort statement

====
But it would make a difference in what cell should be checked for its
emptiness. If you wanted to check row 20 (the header row), then you'd
want to
use that A20:P40 and xlyes.

If you wanted to check the first "data" cell, you'd use the existing code.

Jack Sons wrote:

Dave,

Your answer came fast as lightning, as is your code. Thank you.

About headers, they are in row 20. Makes the use of headers the code
shorter
or faster?

Jack.

"Dave Peterson" schreef in bericht
...
You want each column A21:A40, B21:B40, ..., P21:P40 to be sorted
separately?

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCol As Range

With Worksheets("Sheet1")
Set myRng = .Range("a21:p40")

For Each myCol In myRng.Columns
If IsEmpty(myCol.Cells(1, 1).Value) Then
'skip it
Else
With myCol
.Sort key1:=.Columns(1), order1:=xlAscending,
header:=xlNo
End With
End If
Next myCol
End With
End Sub

I guessed that you don't have headers in the range to sort.



Jack Sons wrote:

Hi all,

I want in each column A to P to sort cells 21 to 40 (some ranges
could
be
empty, if cell 21 is empty so are the others in that column).
I know it can be done with a for next instruction like

For Each xxx In yyy
Do ???
Loop
Next yyy

To my regret I can't figure out what code I need.
I use Excel 2000.

Your help will be appreciated.

Jack Sons
The Netherlands

--

Dave Peterson


--

Dave Peterson





 
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
Further improvement to this IP address sorting code. [email protected] Excel Discussion (Misc queries) 0 May 12th 09 06:28 AM
Sorting in code Ayo Excel Discussion (Misc queries) 4 July 19th 08 11:47 PM
Sorting by code Jay Excel Discussion (Misc queries) 1 February 8th 08 05:55 PM
sorting code Larry Excel Discussion (Misc queries) 5 August 2nd 06 07:40 AM
12 digit code sorting Mark Excel Worksheet Functions 5 October 31st 05 10:21 PM


All times are GMT +1. The time now is 10:13 PM.

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"