copy spreadsheet in new workbook, macro problem

  • Thread starter Thread starter matthias
  • Start date Start date
M

matthias

hi if i run this macro,he copies the 2 spreadsheets as i want, but i
want the 2 copied sheets in the same workbook!! can i do this???


If ActiveWorkbook.Worksheets("sheet1").Range("A1") =
ActiveWorkbook.Worksheets("sheet2").Range("A1") Then
ActiveWorkbook.Worksheets("sheet1").Copy
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

ActiveWorkbook.Worksheets("sheet2").Copy
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

End If





End Sub
 
If ActiveWorkbook.Worksheets("sheet1"). _
Range("A1") = ActiveWorkbook.Worksheets( _
"sheet2").Range("A1") Then
ActiveWorkbook.Worksheets("sheet1").Copy _
After:=Worksheets(Worksheets.count)
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

ActiveWorkbook.Worksheets("sheet2").Copy _
After:=Worksheets(Worksheets.count)
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

End If
 
Hello,

the macro works perfectly!!!
but now he copies the worksheets in the same workbook.
I want to copy the sheets in an existing workbook (for instance:
c:\book1.xls\sheet1 for sheets 1 and so on)

is this possible??
 
Isn't that what you asked for?
i want the 2 copied sheets in the same workbook!!

If this is another question then I gues you are asking to copy to another
existing workbook. I assume the workbook you want to copy to is Book1.xls
located in "C:\" If it isn't open, then open it.


Dim s as String, s1 as String
Dim bk as Workbook, bk1 as Workbook
s = "Book1.xls"
s1 = "C:\" & s

set bk1 = Activeworkbook

On Error Resume next
set bk = Workbooks(s)
On errror goto 0
if bk is nothing then
set bk = Workbooks.Open(s1)
end if

If bk1.Worksheets("sheet1"). _
Range("A1") = bk1.Worksheets( _
"sheet2").Range("A1") Then
bk1.Worksheets("sheet1").Copy _
After:=bk.Worksheets(bk.Worksheets.count)
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

bk1.Worksheets("sheet2").Copy _
After:=bk.Worksheets(bk.Worksheets.count)
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Application.CutCopyMode = False

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top