View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

What you're asking for is doable.

But how about a slightly different approach?

Put all your data on one worksheet. Add a column that corresponds to date. By
putting all the data in one spot, it makes updating easier (or at least more
consistent--like when you add a column, you don't have to add it to several
worksheets.

Then you could use a macro that filters that worksheet (by date and by customer)
and creates the separate worksheets that way.

Debra Dalgleish has some code that comes kind of close to doing this -- but it's
based on only one column. You could tweak that code or you could insert a new
column that combines dates/customers -- so you can treat it as one field.

http://www.contextures.com/excelfiles.html

Create New Sheets from Filtered List -- uses an Advanced Filter to create
separate sheet of orders for each sales rep visible in a filtered list; macro
automates the filter. AdvFilterRepFiltered.xls 35 kb

Update Sheets from Master -- uses an Advanced Filter to send data from
Master sheet to individual worksheets -- replaces old data with current.
AdvFilterCity.xls 55 kb


======
But this may get you started with the original question. Select/group your
sheets (click on the first tab, ctrl-click on the next two tabs.)

Option Explicit
Sub testme01()
Dim Wks As Worksheet
Dim DestCell As Range
Dim newWks As Worksheet
Dim HeadersAreDone As Boolean
Dim mySelectedSheets As Object

Set mySelectedSheets = ActiveWindow.SelectedSheets
If mySelectedSheets.Count < 3 Then
MsgBox "Please Group exactly 3 sheets before you run this macro!"
Exit Sub
End If

Set newWks = Workbooks.Add(1).Worksheets(1)
HeadersAreDone = False
For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(1).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell
End With
With newWks
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
Next Wks

'delete columns you don't want.

End Sub

Remember to ungroup the sheets when you're done. Anything you do to one of
those sheets, you do to all 3!

So you can really hose up a workbook really fast!

And after you have the 3 worksheets combined, you could still use code from
Debra's site to break them apart per customer.

Pank Mehta wrote:

Copying multiple sheets from one book 2 another and undertake special editing.

Apologies as the following is long winded.

I have a workbook that has 12 sheets (i.e. 1 for each month of the Year).
Each sheet contains the following: -

Header row;
Customer name; date contacted and work location (and other information).
One can have multiple rows for each customer as they can contact us many
times a day for work to be undertaken at different locations.

On a monthly basis we have to undertake a charging process for customers who
have used our services for the last month.

At the moment we all copy the information from each monthly sheet to another
workbook and sort it on Customer name.

Having sorted the information, someone manually creates a worksheet for each
customer using Cut + Paste and then creates an invoice.

Things have now changed and we have to charge on a quarterly basis.

Is there any way that a front-end screen can be written in which one
specifies sheet names that need to be charged for and a destination sheet
name. Once the sheet names have been entered, we would like the appropriate
sheets (may be selected columns) to be copied to an existing workbook (using
Paste special and Values) with the name specified as destination. Obviously
once the sheets have been copied, there will be three headers, I would
ideally like to search the destination sheet and delete the extra 2 headers
automatically before it is sorted in the format that is required.

Having sorted the sheet, we would like to create individual sheets for all
the different customers that exist on the master sheet and have all rows for
that customer copied into their named sheet.

Any help offered would be most appreciated.


--

Dave Peterson