Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 29
Default sorting and copying

dont know if this it to much to do via a script but here goes
i have a file with 700 lines or so by 14 columns of data , in the 4th column
i have a list of numbers ,
what i am after is someway of when a change in the number in the 4th column
appears,select all the data above with the same number and either copy/cut
that data to a new file or even a new tab (naming that tab to the same as the
number) in the same file , then continue till the next change in column 4
and so on till the page is empty. so i end up with a file full of tabs for
each number change....

maybe its to much , thanks for trying in advance
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 791
Default sorting and copying

Try sorting all 14 columns based on column 4 (ascending or descending it
doesn't matter) then place a filter on column 4 your code should be a for
next loop. Inside the loop will go the filtering based on x and the selection
of the visible area plus cutting or copying to a new page. Maybe you should
post in the excel.coding and not on this board. Just a suggestion.
i.e.:

for i=x to y

next x

Michael Arch.

"Stan Halls" wrote:

dont know if this it to much to do via a script but here goes
i have a file with 700 lines or so by 14 columns of data , in the 4th column
i have a list of numbers ,
what i am after is someway of when a change in the number in the 4th column
appears,select all the data above with the same number and either copy/cut
that data to a new file or even a new tab (naming that tab to the same as the
number) in the same file , then continue till the next change in column 4
and so on till the page is empty. so i end up with a file full of tabs for
each number change....

maybe its to much , thanks for trying in advance

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default sorting and copying

Stan,

Select a cell withing your database, and then un the macro below.

Answer 4 when asked..."What column # within database to use as key?"

HTH,
Bernie
MS Excel MVP


Sub ExportDatabaseToSeparateSheets()
'Export is based on the value in the desired column
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String
Dim myArea As Range
Dim myShtName As String
Dim KeyCol As Integer

myShtName = ActiveSheet.Name
KeyCol = InputBox("What column # within database to use as key?")


Set myArea = ActiveCell.CurrentRegion.Columns(KeyCol).Offset(1, 0).Cells

Set myArea = myArea.Resize(myArea.Rows.Count - 1, 1)

For Each myCell In myArea
On Error GoTo NoSheet
myName =Worksheets(CStr(myCell.Value)).Name
GoTo SheetExists:
NoSheet:
Set mySht = Worksheets.Add(Befo=Worksheets(1))
mySht.Name = CStr(myCell.Value)
With myCell.CurrentRegion
.AutoFilter Field:=KeyCol, Criteria1:=myCell.Value
'These lines copy everything - including extra header rows
' and any SUBTOTAL formulas separated by blank row
'Uncomment them to use them
' myCell.Parent.Cells.SpecialCells(xlCellTypeVisible ).Copy
' mySht.Range("A1").PasteSpecial xlPasteValues


'These are the default - only copy the database values
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
.AutoFilter
End With
Resume
SheetExists:
Next myCell

End Sub



"Stan Halls" wrote in message
...
dont know if this it to much to do via a script but here goes
i have a file with 700 lines or so by 14 columns of data , in the 4th column
i have a list of numbers ,
what i am after is someway of when a change in the number in the 4th column
appears,select all the data above with the same number and either copy/cut
that data to a new file or even a new tab (naming that tab to the same as the
number) in the same file , then continue till the next change in column 4
and so on till the page is empty. so i end up with a file full of tabs for
each number change....

maybe its to much , thanks for trying in advance



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 29
Default sorting and copying

Brenie
Magic, thats just what i wanted , thanks for taking the time to do
that

"Bernie Deitrick" wrote:

Stan,

Select a cell withing your database, and then un the macro below.

Answer 4 when asked..."What column # within database to use as key?"

HTH,
Bernie
MS Excel MVP


Sub ExportDatabaseToSeparateSheets()
'Export is based on the value in the desired column
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String
Dim myArea As Range
Dim myShtName As String
Dim KeyCol As Integer

myShtName = ActiveSheet.Name
KeyCol = InputBox("What column # within database to use as key?")


Set myArea = ActiveCell.CurrentRegion.Columns(KeyCol).Offset(1, 0).Cells

Set myArea = myArea.Resize(myArea.Rows.Count - 1, 1)

For Each myCell In myArea
On Error GoTo NoSheet
myName =Worksheets(CStr(myCell.Value)).Name
GoTo SheetExists:
NoSheet:
Set mySht = Worksheets.Add(Befo=Worksheets(1))
mySht.Name = CStr(myCell.Value)
With myCell.CurrentRegion
.AutoFilter Field:=KeyCol, Criteria1:=myCell.Value
'These lines copy everything - including extra header rows
' and any SUBTOTAL formulas separated by blank row
'Uncomment them to use them
' myCell.Parent.Cells.SpecialCells(xlCellTypeVisible ).Copy
' mySht.Range("A1").PasteSpecial xlPasteValues


'These are the default - only copy the database values
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
.AutoFilter
End With
Resume
SheetExists:
Next myCell

End Sub



"Stan Halls" wrote in message
...
dont know if this it to much to do via a script but here goes
i have a file with 700 lines or so by 14 columns of data , in the 4th column
i have a list of numbers ,
what i am after is someway of when a change in the number in the 4th column
appears,select all the data above with the same number and either copy/cut
that data to a new file or even a new tab (naming that tab to the same as the
number) in the same file , then continue till the next change in column 4
and so on till the page is empty. so i end up with a file full of tabs for
each number change....

maybe its to much , thanks for trying in advance




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
copying the Hyperlink function result without copying the actual formula mcheng Excel Worksheet Functions 2 June 9th 07 02:43 AM
preparing pivot fields for copying and paste special for sorting rsmith333 Excel Discussion (Misc queries) 2 June 4th 07 01:21 PM
Autofilter/Sorting Copying Wrong records Sandi Excel Discussion (Misc queries) 3 January 22nd 07 11:28 PM
Sorting and copying data to another worksheet in a workbook. Geo Excel Discussion (Misc queries) 3 June 5th 06 09:58 PM
Sorting and copying automatically between worksheets nadia New Users to Excel 2 February 12th 06 10:18 PM


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