Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default separate each sort order ?

Hi
How do I separate each sort order and move to next blank column with heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default separate each sort order ?

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in message
...
Hi
How do I separate each sort order and move to next blank column with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default separate each sort order ?

Thanks Mike Fogleman for reply
When i run Sub copyfilter() it gives Runtime error '91'
Object Variable or with Black Variable not set.
My data is like....

Date,Group,Name,In,Out.
I am sorting data as per Group

Any idea.
Thanks

****al

"Mike Fogleman" wrote:

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in message
...
Hi
How do I separate each sort order and move to next blank column with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default separate each sort order ?

You mean on this line:
With ActiveSheet.AutoFilter.Range

that is probably because you don't have an autofilter on your data.

I am not sure what you want to do and Mike probably was just guessing as
well. Perhaps a clearer statement of your problem.

Your macro should work - what part do you want to change. Just make the area
in column 1 dynamic?

Sub changeorder()
Range("A4").Select
set rng = Range(Range("A1"),Range("A1").end(xldown))
rng.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)
End Sub


--
Regards,
Tom Ogilvy



"****al shah" wrote in message
...
Thanks Mike Fogleman for reply
When i run Sub copyfilter() it gives Runtime error '91'
Object Variable or with Black Variable not set.
My data is like....

Date,Group,Name,In,Out.
I am sorting data as per Group

Any idea.
Thanks

****al

"Mike Fogleman" wrote:

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in message
...
Hi
How do I separate each sort order and move to next blank column with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending,

Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default separate each sort order ?

Thnaks Tom Ogilvy
the code which i have given is working fine. But i have a problem is that
when i Sort data than after when sort order change it should move that data
into next column.
Any help
thanks Again
****al

"Tom Ogilvy" wrote:

You mean on this line:
With ActiveSheet.AutoFilter.Range

that is probably because you don't have an autofilter on your data.

I am not sure what you want to do and Mike probably was just guessing as
well. Perhaps a clearer statement of your problem.

Your macro should work - what part do you want to change. Just make the area
in column 1 dynamic?

Sub changeorder()
Range("A4").Select
set rng = Range(Range("A1"),Range("A1").end(xldown))
rng.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)
End Sub


--
Regards,
Tom Ogilvy



"****al shah" wrote in message
...
Thanks Mike Fogleman for reply
When i run Sub copyfilter() it gives Runtime error '91'
Object Variable or with Black Variable not set.
My data is like....

Date,Group,Name,In,Out.
I am sorting data as per Group

Any idea.
Thanks

****al

"Mike Fogleman" wrote:

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in message
...
Hi
How do I separate each sort order and move to next blank column with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending,

Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default separate each sort order ?

It does that now. Each time you run the macro, it should sort the data and
copy the sorted data to the next available column.

If you want to copy the old data before you sort it, move this line to the
top of the macro:

Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)


--
Regards,
Tom Ogilvy

"****al shah" wrote in message
...
Thnaks Tom Ogilvy
the code which i have given is working fine. But i have a problem is that
when i Sort data than after when sort order change it should move that

data
into next column.
Any help
thanks Again
****al

"Tom Ogilvy" wrote:

You mean on this line:
With ActiveSheet.AutoFilter.Range

that is probably because you don't have an autofilter on your data.

I am not sure what you want to do and Mike probably was just guessing as
well. Perhaps a clearer statement of your problem.

Your macro should work - what part do you want to change. Just make the

area
in column 1 dynamic?

Sub changeorder()
Range("A4").Select
set rng = Range(Range("A1"),Range("A1").end(xldown))
rng.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)
End Sub


--
Regards,
Tom Ogilvy



"****al shah" wrote in message
...
Thanks Mike Fogleman for reply
When i run Sub copyfilter() it gives Runtime error '91'
Object Variable or with Black Variable not set.
My data is like....

Date,Group,Name,In,Out.
I am sorting data as per Group

Any idea.
Thanks

****al

"Mike Fogleman" wrote:

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in

message
...
Hi
How do I separate each sort order and move to next blank column

with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending,

Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default separate each sort order ?

thanks again Tom But what i want is .... E.G.

If sort Region East,west,north and south
Than When Esat is over than only East from the List should move from the
list to next column and afteronly North move to next coulmn ...and so on...

Any help

****al

"Tom Ogilvy" wrote:

It does that now. Each time you run the macro, it should sort the data and
copy the sorted data to the next available column.

If you want to copy the old data before you sort it, move this line to the
top of the macro:

Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)


--
Regards,
Tom Ogilvy

"****al shah" wrote in message
...
Thnaks Tom Ogilvy
the code which i have given is working fine. But i have a problem is that
when i Sort data than after when sort order change it should move that

data
into next column.
Any help
thanks Again
****al

"Tom Ogilvy" wrote:

You mean on this line:
With ActiveSheet.AutoFilter.Range

that is probably because you don't have an autofilter on your data.

I am not sure what you want to do and Mike probably was just guessing as
well. Perhaps a clearer statement of your problem.

Your macro should work - what part do you want to change. Just make the

area
in column 1 dynamic?

Sub changeorder()
Range("A4").Select
set rng = Range(Range("A1"),Range("A1").end(xldown))
rng.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2)
End Sub


--
Regards,
Tom Ogilvy



"****al shah" wrote in message
...
Thanks Mike Fogleman for reply
When i run Sub copyfilter() it gives Runtime error '91'
Object Variable or with Black Variable not set.
My data is like....

Date,Group,Name,In,Out.
I am sorting data as per Group

Any idea.
Thanks

****al

"Mike Fogleman" wrote:

See if you can modify these to your needs.
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData

End Sub

Sub FilterData()
'by Bob Phillips
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & iLastRow)
.AutoFilter Field:=1, Criteria1:="SC"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="SU"
.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Destination:=Worksheets("Sheet3").Range("A1")
.AutoFilter
End With
End Sub

Mike F
"****al shah" wrote in

message
...
Hi
How do I separate each sort order and move to next blank column

with
heading
and also how I automatically change range of data.


Sub changeorder()
Range("A4").Select
Range("A1:A110").Sort Key1:=Range("A2"), Order1:=xlAscending,
Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(1).Copy Cells(1, 256).End(xlToLeft)(1, 2).EntireColumn
End Sub











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
Can three separate sections of rows be sorted in the same order? Jacquiemal Excel Worksheet Functions 1 February 11th 09 06:57 PM
How to insert macro results on a separate spreadsheet in row order andrewc Excel Discussion (Misc queries) 1 January 19th 09 05:43 PM
Retaining Sort order in the Sort Dialog box CBittinger Excel Discussion (Misc queries) 2 January 9th 08 05:01 PM
Sort sheet based on particuilar sort order Also Excel Worksheet Functions 4 January 3rd 08 09:31 AM
Pls. reply Sort Data and copy to next coulmn when sort order chang shital shah Excel Programming 1 August 19th 05 02:51 PM


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