Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default sorting multiple-area selection

Dear friends

Is it possible to select in one column only those cells with data and to
sort them with code? for example:

A1
A2 2
A3 1
A4 3
A5
A6 6
A7 5

And I want it to be:
A1
A2 1
A3 2
A4 3
A5
A6 5
A7 6

Thanks in advance for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default sorting multiple-area selection

Still finetuning this, but to give you what I have so far before I go
into lunch break:

Public Sub sortNotEmpty()
Dim ws As Worksheet

Set ws = ActiveSheet

ws.Range("A1:A100").AutoFilter 1, "0"
ws.Range("A1:B100").Sort ws.Range("A1"), xlAscending
ws.AutoFilterMode = False
End Sub


This does what you want, but if the first line is empty, it puts the
sort-filter there and somehow afterwards doesn't put the empty line
back. So need to work around this somehow. Otherwise, the above function
does what you want - might need to work on the filter criteria though.

Best Regards,

Lars
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default sorting multiple-area selection

If those values in column A are typed in -- not formulas, then this may work for
you:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myArea As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a:a").Cells.SpecialCells(xlCellTypeConstan ts)
On Error GoTo 0
End With

If myRng Is Nothing Then
MsgBox "No constants here!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, header:=xlNo
End With
Next myArea

End Sub




??? wrote:

Dear friends

Is it possible to select in one column only those cells with data and to
sort them with code? for example:

A1
A2 2
A3 1
A4 3
A5
A6 6
A7 5

And I want it to be:
A1
A2 1
A3 2
A4 3
A5
A6 5
A7 6

Thanks in advance for your help.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default sorting multiple-area selection

Hi Dave

Your code sorts each area, which may or may not be what the OP wants. It
could be that the sorting musst be over all numbers in the areas.

But then the OP will tell us... ;-)

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Dave Peterson" wrote:

If those values in column A are typed in -- not formulas, then this may work for
you:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myArea As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a:a").Cells.SpecialCells(xlCellTypeConstan ts)
On Error GoTo 0
End With

If myRng Is Nothing Then
MsgBox "No constants here!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, header:=xlNo
End With
Next myArea

End Sub




??? wrote:

Dear friends

Is it possible to select in one column only those cells with data and to
sort them with code? for example:

A1
A2 2
A3 1
A4 3
A5
A6 6
A7 5

And I want it to be:
A1
A2 1
A3 2
A4 3
A5
A6 5
A7 6

Thanks in advance for your help.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default sorting multiple-area selection

Could be...

But I'd be pretty surprised. I've seen many requests to sort each area. I'm
not sure I've ever seen anyone to sort all the data in order, but keep the empty
rows intact.



Wigi wrote:

Hi Dave

Your code sorts each area, which may or may not be what the OP wants. It
could be that the sorting musst be over all numbers in the areas.

But then the OP will tell us... ;-)

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music

"Dave Peterson" wrote:

If those values in column A are typed in -- not formulas, then this may work for
you:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myArea As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a:a").Cells.SpecialCells(xlCellTypeConstan ts)
On Error GoTo 0
End With

If myRng Is Nothing Then
MsgBox "No constants here!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, header:=xlNo
End With
Next myArea

End Sub




??? wrote:

Dear friends

Is it possible to select in one column only those cells with data and to
sort them with code? for example:

A1
A2 2
A3 1
A4 3
A5
A6 6
A7 5

And I want it to be:
A1
A2 1
A3 2
A4 3
A5
A6 5
A7 6

Thanks in advance for your help.


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default sorting multiple-area selection

Thank you all. I have found all your suggestions perfect for me (with few
adjustments...)

Eli

"Dave Peterson" wrote:

Could be...

But I'd be pretty surprised. I've seen many requests to sort each area. I'm
not sure I've ever seen anyone to sort all the data in order, but keep the empty
rows intact.



Wigi wrote:

Hi Dave

Your code sorts each area, which may or may not be what the OP wants. It
could be that the sorting musst be over all numbers in the areas.

But then the OP will tell us... ;-)

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music

"Dave Peterson" wrote:

If those values in column A are typed in -- not formulas, then this may work for
you:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myArea As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a:a").Cells.SpecialCells(xlCellTypeConstan ts)
On Error GoTo 0
End With

If myRng Is Nothing Then
MsgBox "No constants here!"
Exit Sub
End If

For Each myArea In myRng.Areas
With myArea
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, header:=xlNo
End With
Next myArea

End Sub




??? wrote:

Dear friends

Is it possible to select in one column only those cells with data and to
sort them with code? for example:

A1
A2 2
A3 1
A4 3
A5
A6 6
A7 5

And I want it to be:
A1
A2 1
A3 2
A4 3
A5
A6 5
A7 6

Thanks in advance for your help.

--

Dave Peterson


--

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
How do I keep the selection box in the work area Ken Dean Excel Discussion (Misc queries) 2 June 27th 06 09:45 PM
Non-adjacent area selection rjamison Excel Programming 0 June 14th 05 12:14 AM
Non-adjacent area selection rjamison Excel Programming 0 June 14th 05 12:14 AM
Non-adjacent area selection Petr Excel Programming 1 April 20th 05 03:05 PM
Multiple selection in the page area of a pivot table svlach Excel Discussion (Misc queries) 0 March 10th 05 03:33 PM


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