Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Pank Mehta
 
Posts: n/a
Default Copying multiple sheets from one book 2 another and undertake spec

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.



  #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
  #3   Report Post  
Ann
 
Posts: n/a
Default

Dave,

Firstly, many thanks for your help. However, I am now encountering the
following problem.

"Compile Error : Expected End With" and the only End With in the code is
highlighted in yellow when I select debug.

Detailed below is the code that I have:-

Sub EOM()
Dim Wks As Worksheet
Dim DestCell As Range
Dim newWks As Worksheet
Dim HeadersAreDone As Boolean
Dim mySelectedSheets As Object
Dim myRngToCopy As Range
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
ActiveWorkbook.Unprotect
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
With Worksheets("sheet1")
.Unprotect password:=""
Set myRngToCopy = .Range("a2",
..Cells.SpecialCells(xlCellTypeLastCell))
DestCell.Resize(myRngToCopy.Rows.Count,
myRngToCopy.Columns.Count).Value _
= myRngToCopy.Value
.Protect password:=""
End With
With newWks
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
'Next Wks
'delete columns you don't want.
End With
End Sub

"Dave Peterson" wrote:

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

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm not sure if this works, but it compiled for me:

Option Explicit

Sub EOM()
Dim Wks As Worksheet
Dim DestCell As Range
Dim newWks As Worksheet
Dim HeadersAreDone As Boolean
Dim mySelectedSheets As Object
Dim myRngToCopy As Range

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

ActiveWorkbook.Unprotect

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

With Worksheets("sheet1")
.Unprotect Password:=""
Set myRngToCopy = .Range("a2", _
.Cells.SpecialCells(xlCellTypeLastCell))
DestCell.Resize(myRngToCopy.Rows.Count, _
myRngToCopy.Columns.Count).Value _
= myRngToCopy.Value
.Protect Password:=""
End With

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

I added an End With and moved the workbook protection out of the loop. You may
want to turn that workbook protection back on when your macro is done.

Ann wrote:

Dave,

Firstly, many thanks for your help. However, I am now encountering the
following problem.

"Compile Error : Expected End With" and the only End With in the code is
highlighted in yellow when I select debug.

Detailed below is the code that I have:-

Sub EOM()
Dim Wks As Worksheet
Dim DestCell As Range
Dim newWks As Worksheet
Dim HeadersAreDone As Boolean
Dim mySelectedSheets As Object
Dim myRngToCopy As Range
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
ActiveWorkbook.Unprotect
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
With Worksheets("sheet1")
.Unprotect password:=""
Set myRngToCopy = .Range("a2",
.Cells.SpecialCells(xlCellTypeLastCell))
DestCell.Resize(myRngToCopy.Rows.Count,
myRngToCopy.Columns.Count).Value _
= myRngToCopy.Value
.Protect password:=""
End With
With newWks
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
'Next Wks
'delete columns you don't want.
End With
End Sub

"Dave Peterson" wrote:

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


--

Dave Peterson
  #5   Report Post  
Pank Mehta
 
Posts: n/a
Default

Dave,

Many thanks for your valuable comments and suggestion. I will talk to the
people regarding your suggestion and see what their view are and will also
look at the site you mention.

Once again many thanks.

"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.





  #6   Report Post  
Ann
 
Posts: n/a
Default

Dave,

I have finally, got round to testing the code that you were kind enough to
provide.

Having run the code I get the message "Run Time error 1004, You cannot use
this command on a protected sheet. To unprotect ....". When I click on the
debug statement it points to the line with the following code:-

..Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell

I inserted "ActiveWorkbook.Unprotect" prior to the above statement and also
prior to the first IF statement, but unfortunately this does not resolve the
problem.

It has managed to copy the first sheet, inserted the data onto a new sheet
and then produces the above message.

Lastly, on the copy how do I change it so that it does a special and copies
values as opposed to formulas.

Help much appreciated.

"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.



  #7   Report Post  
Dave Peterson
 
Posts: n/a
Default

First, by directing this to me, you do limit the number of response from
others. And that will hurt you in the long run--lots of people could have
helped.

Second, you have to unprotect the worksheet.

activesheet.unprotect password:="yourpasswordhere"

(I don't recall if this was for the activesheet or some other sheet, though.)

But from the snippet of code you posted, it should fit in right before this
line:

.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell
.protect password:="yourpasswordhere"


And if you only want the values, you can either copy|paste special values or
just assign the value.

dim myRngToCopy as range
'...some more code
with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
set myrngtocopy = .Range("a2", .Cells.SpecialCells(xlCellTypeLastCell))
destcell.resize(myrngtocopy.rows.count,myrngtocopy .columns.count).value _
= myrngtocopy.value
.protect password:="yourpasswordhere"
end with

======
or equivalently:

with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).copy
destcell.pastespecial paste:=xlpastevalues
.protect password:="yourpasswordhere"
end with

I like the assignment of values myself.

Ann wrote:

Dave,

I have finally, got round to testing the code that you were kind enough to
provide.

Having run the code I get the message "Run Time error 1004, You cannot use
this command on a protected sheet. To unprotect ....". When I click on the
debug statement it points to the line with the following code:-

.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell

I inserted "ActiveWorkbook.Unprotect" prior to the above statement and also
prior to the first IF statement, but unfortunately this does not resolve the
problem.

It has managed to copy the first sheet, inserted the data onto a new sheet
and then produces the above message.

Lastly, on the copy how do I change it so that it does a special and copies
values as opposed to formulas.

Help much appreciated.

"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
  #8   Report Post  
Pank Mehta
 
Posts: n/a
Default

Dave,

Sorry to be a pain in A**E.

The code I have is:-

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

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

ActiveWorkbook.Unprotect

For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(2).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If

With Worksheets("someworksheet")
.Unprotect password:=""
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy
DestCell.PasteSpecial Paste:=xlPasteValues
.Protect password:=""
End With

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

Unfortunately, I get the message "subscript out of range". Please help.
Woulf it help if we communicate directly via emails?. Once we (well you) have
cracked it I would still post the full result to the newsgroup just in case
it is usefull to other people?

"Dave Peterson" wrote:

First, by directing this to me, you do limit the number of response from
others. And that will hurt you in the long run--lots of people could have
helped.

Second, you have to unprotect the worksheet.

activesheet.unprotect password:="yourpasswordhere"

(I don't recall if this was for the activesheet or some other sheet, though.)

But from the snippet of code you posted, it should fit in right before this
line:

.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell
.protect password:="yourpasswordhere"


And if you only want the values, you can either copy|paste special values or
just assign the value.

dim myRngToCopy as range
'...some more code
with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
set myrngtocopy = .Range("a2", .Cells.SpecialCells(xlCellTypeLastCell))
destcell.resize(myrngtocopy.rows.count,myrngtocopy .columns.count).value _
= myrngtocopy.value
.protect password:="yourpasswordhere"
end with

======
or equivalently:

with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).copy
destcell.pastespecial paste:=xlpastevalues
.protect password:="yourpasswordhere"
end with

I like the assignment of values myself.

Ann wrote:

Dave,

I have finally, got round to testing the code that you were kind enough to
provide.

Having run the code I get the message "Run Time error 1004, You cannot use
this command on a protected sheet. To unprotect ....". When I click on the
debug statement it points to the line with the following code:-

.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell

I inserted "ActiveWorkbook.Unprotect" prior to the above statement and also
prior to the first IF statement, but unfortunately this does not resolve the
problem.

It has managed to copy the first sheet, inserted the data onto a new sheet
and then produces the above message.

Lastly, on the copy how do I change it so that it does a special and copies
values as opposed to formulas.

Help much appreciated.

"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

  #9   Report Post  
Dave Peterson
 
Posts: n/a
Default

That snippet could have been editted when you merged it with the existing code:

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

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

ActiveWorkbook.Unprotect

For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(2).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If

.Unprotect password:=""
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy
DestCell.PasteSpecial Paste:=xlPasteValues
.Protect password:=""

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

I deleted the "With Worksheets("someworksheet")" and associated "end with"
statements.

Pank Mehta wrote:

Dave,

Sorry to be a pain in A**E.

The code I have is:-

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

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

ActiveWorkbook.Unprotect

For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(2).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If

With Worksheets("someworksheet")
.Unprotect password:=""
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy
DestCell.PasteSpecial Paste:=xlPasteValues
.Protect password:=""
End With

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

Unfortunately, I get the message "subscript out of range". Please help.
Woulf it help if we communicate directly via emails?. Once we (well you) have
cracked it I would still post the full result to the newsgroup just in case
it is usefull to other people?

"Dave Peterson" wrote:

First, by directing this to me, you do limit the number of response from
others. And that will hurt you in the long run--lots of people could have
helped.

Second, you have to unprotect the worksheet.

activesheet.unprotect password:="yourpasswordhere"

(I don't recall if this was for the activesheet or some other sheet, though.)

But from the snippet of code you posted, it should fit in right before this
line:

.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell
.protect password:="yourpasswordhere"


And if you only want the values, you can either copy|paste special values or
just assign the value.

dim myRngToCopy as range
'...some more code
with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
set myrngtocopy = .Range("a2", .Cells.SpecialCells(xlCellTypeLastCell))
destcell.resize(myrngtocopy.rows.count,myrngtocopy .columns.count).value _
= myrngtocopy.value
.protect password:="yourpasswordhere"
end with

======
or equivalently:

with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).copy
destcell.pastespecial paste:=xlpastevalues
.protect password:="yourpasswordhere"
end with

I like the assignment of values myself.

Ann wrote:

Dave,

I have finally, got round to testing the code that you were kind enough to
provide.

Having run the code I get the message "Run Time error 1004, You cannot use
this command on a protected sheet. To unprotect ....". When I click on the
debug statement it points to the line with the following code:-

.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell

I inserted "ActiveWorkbook.Unprotect" prior to the above statement and also
prior to the first IF statement, but unfortunately this does not resolve the
problem.

It has managed to copy the first sheet, inserted the data onto a new sheet
and then produces the above message.

Lastly, on the copy how do I change it so that it does a special and copies
values as opposed to formulas.

Help much appreciated.

"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


--

Dave Peterson
  #10   Report Post  
Pank Mehta
 
Posts: n/a
Default

Dave,

Having copied the latest code I get a "400" error.

"Dave Peterson" wrote:

That snippet could have been editted when you merged it with the existing code:

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

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

ActiveWorkbook.Unprotect

For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(2).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If

.Unprotect password:=""
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy
DestCell.PasteSpecial Paste:=xlPasteValues
.Protect password:=""

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

I deleted the "With Worksheets("someworksheet")" and associated "end with"
statements.

Pank Mehta wrote:

Dave,

Sorry to be a pain in A**E.

The code I have is:-

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

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

ActiveWorkbook.Unprotect

For Each Wks In mySelectedSheets
With Wks
If HeadersAreDone = True Then
'do nothing
Else
.Rows(2).Copy _
Destination:=newWks.Range("a1")
HeadersAreDone = True
Set DestCell = newWks.Range("a2")
End If

With Worksheets("someworksheet")
.Unprotect password:=""
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy
DestCell.PasteSpecial Paste:=xlPasteValues
.Protect password:=""
End With

Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)

End With
Next Wks

End Sub

Unfortunately, I get the message "subscript out of range". Please help.
Woulf it help if we communicate directly via emails?. Once we (well you) have
cracked it I would still post the full result to the newsgroup just in case
it is usefull to other people?

"Dave Peterson" wrote:

First, by directing this to me, you do limit the number of response from
others. And that will hurt you in the long run--lots of people could have
helped.

Second, you have to unprotect the worksheet.

activesheet.unprotect password:="yourpasswordhere"

(I don't recall if this was for the activesheet or some other sheet, though.)

But from the snippet of code you posted, it should fit in right before this
line:

.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell
.protect password:="yourpasswordhere"


And if you only want the values, you can either copy|paste special values or
just assign the value.

dim myRngToCopy as range
'...some more code
with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
set myrngtocopy = .Range("a2", .Cells.SpecialCells(xlCellTypeLastCell))
destcell.resize(myrngtocopy.rows.count,myrngtocopy .columns.count).value _
= myrngtocopy.value
.protect password:="yourpasswordhere"
end with

======
or equivalently:

with worksheets("someworksheet")
.unprotect password:="yourpasswordhere"
.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).copy
destcell.pastespecial paste:=xlpastevalues
.protect password:="yourpasswordhere"
end with

I like the assignment of values myself.

Ann wrote:

Dave,

I have finally, got round to testing the code that you were kind enough to
provide.

Having run the code I get the message "Run Time error 1004, You cannot use
this command on a protected sheet. To unprotect ....". When I click on the
debug statement it points to the line with the following code:-

.Range("a2", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=DestCell

I inserted "ActiveWorkbook.Unprotect" prior to the above statement and also
prior to the first IF statement, but unfortunately this does not resolve the
problem.

It has managed to copy the first sheet, inserted the data onto a new sheet
and then produces the above message.

Lastly, on the copy how do I change it so that it does a special and copies
values as opposed to formulas.

Help much appreciated.

"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


--

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



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