Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Dynamic Macro Input

I am trying to create a Macro that will sort a multi-column, multi-row
set of data. Sorting on one column is simple using the Excel built in
sort function. Once the sorting is complete, I would like the macro
to take each unique set of data, by row, and create a new spreadsheet
with just that data included.

What I am finding difficult is to have the macro dynamically sense
which data belongs together, then copy and paste it into a new sheet.
Is there some stock code that someone has to do this or is there a
function in Excel that I can readily use? I've been stumped by this
for a while.

Thanks in advance!

craig.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Dynamic Macro Input

Craig

I think you're going to have to tell us what the rules are so that we know
"which data belongs together"

Are you saying that you need a new sheet for each row of data ?

Something like this might do what you want:

Sub NewSheets()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A65536").End(xlUp).Row
For i = 1 To LastRow
Set NewSheet = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
NewSheet.Name = "data " & i
Sheets("Sheet1").Range("A" & i).EntireRow.Copy NewSheet.Range("A1")
Next 'i
End Sub

Assumes that the "master" sheet is Sheet1

Regards

Trevor


"Craig" wrote in message
om...
I am trying to create a Macro that will sort a multi-column, multi-row
set of data. Sorting on one column is simple using the Excel built in
sort function. Once the sorting is complete, I would like the macro
to take each unique set of data, by row, and create a new spreadsheet
with just that data included.

What I am finding difficult is to have the macro dynamically sense
which data belongs together, then copy and paste it into a new sheet.
Is there some stock code that someone has to do this or is there a
function in Excel that I can readily use? I've been stumped by this
for a while.

Thanks in advance!

craig.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Dynamic Macro Input

Thanks for the feedback so far. This looks like it might be along the
lines of what I need.

Based upon an initial sort that I do (this will be part of the macro),
I am able to see that there should be anywhere from 1-10 rows that
belong together (same data value) in a new sheet.

Seems like I need to scan the document to determine which rows belong
together, create a new sheet, copy the data there and start the
process again until all the rows have been copied to new sheets. Does
this help?

Thanks in advance!

craig.

"Trevor Shuttleworth" wrote in message ...
Craig

I think you're going to have to tell us what the rules are so that we know
"which data belongs together"

Are you saying that you need a new sheet for each row of data ?

Something like this might do what you want:

Sub NewSheets()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A65536").End(xlUp).Row
For i = 1 To LastRow
Set NewSheet = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
NewSheet.Name = "data " & i
Sheets("Sheet1").Range("A" & i).EntireRow.Copy NewSheet.Range("A1")
Next 'i
End Sub

Assumes that the "master" sheet is Sheet1

Regards

Trevor


"Craig" wrote in message
om...
I am trying to create a Macro that will sort a multi-column, multi-row
set of data. Sorting on one column is simple using the Excel built in
sort function. Once the sorting is complete, I would like the macro
to take each unique set of data, by row, and create a new spreadsheet
with just that data included.

What I am finding difficult is to have the macro dynamically sense
which data belongs together, then copy and paste it into a new sheet.
Is there some stock code that someone has to do this or is there a
function in Excel that I can readily use? I've been stumped by this
for a while.

Thanks in advance!

craig.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Dynamic Macro Input

Craig

try something like this:

Sub CreateNewSheets()
Dim MasterSheet As Worksheet
Dim NewSheet As Worksheet
Dim LastRow As Long
Dim i As Long
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set MasterSheet = Worksheets("Sheet1")
With MasterSheet
LastRow = .Range("A65536").End(xlUp).Row
.Range("A1").Sort _
Key1:=.Range("A2"), _
Order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
End With
With MasterSheet
For i = 2 To LastRow
If .Range("A" & i) < .Range("A" & i).Offset(-1, 0) Then
Set NewSheet =
Worksheets.Add(after:=Worksheets(Worksheets.Count) )
NewSheet.Name = MasterSheet.Range("A" & i).Value
.Range("A1").EntireRow.Copy NewSheet.Range("A1")
End If
.Range("A" & i).EntireRow.Copy
With NewSheet
.Range("A65536").End(xlUp).Offset(1, 0).Select
.Paste
Application.CutCopyMode = False
End With
Next 'i
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
On Error GoTo 0
End Sub

Probably not the most efficient but it should be OK for a relatively small
number of rows. Note that if it is rerun it won't name the worksheets. It
would be better to build a range to be copied and then copy and paste once
for each change of key value ... but that can be your challenge !

Regards

Trevor


"Craig" wrote in message
om...
Thanks for the feedback so far. This looks like it might be along the
lines of what I need.

Based upon an initial sort that I do (this will be part of the macro),
I am able to see that there should be anywhere from 1-10 rows that
belong together (same data value) in a new sheet.

Seems like I need to scan the document to determine which rows belong
together, create a new sheet, copy the data there and start the
process again until all the rows have been copied to new sheets. Does
this help?

Thanks in advance!

craig.

"Trevor Shuttleworth" wrote in message

...
Craig

I think you're going to have to tell us what the rules are so that we

know
"which data belongs together"

Are you saying that you need a new sheet for each row of data ?

Something like this might do what you want:

Sub NewSheets()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A65536").End(xlUp).Row
For i = 1 To LastRow
Set NewSheet = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
NewSheet.Name = "data " & i
Sheets("Sheet1").Range("A" & i).EntireRow.Copy NewSheet.Range("A1")
Next 'i
End Sub

Assumes that the "master" sheet is Sheet1

Regards

Trevor


"Craig" wrote in message
om...
I am trying to create a Macro that will sort a multi-column, multi-row
set of data. Sorting on one column is simple using the Excel built in
sort function. Once the sorting is complete, I would like the macro
to take each unique set of data, by row, and create a new spreadsheet
with just that data included.

What I am finding difficult is to have the macro dynamically sense
which data belongs together, then copy and paste it into a new sheet.
Is there some stock code that someone has to do this or is there a
function in Excel that I can readily use? I've been stumped by this
for a while.

Thanks in advance!

craig.



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
Dynamic Sum Array Formula Input Help excelCPA Excel Discussion (Misc queries) 3 September 25th 09 06:40 PM
Dynamic report based on user input C02C04 Excel Discussion (Misc queries) 7 November 26th 08 03:45 PM
run macro with input msg based on cell input Janelle S Excel Discussion (Misc queries) 0 January 20th 08 05:23 AM
macro with dynamic input Ahmaq Excel Worksheet Functions 2 April 24th 07 01:06 PM
Dynamic input for Chart gives error9 but seems to do his job to... the dude Excel Programming 0 October 17th 03 03:56 PM


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"