Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50110

why excel creates two new worksheets instead of one using this code?

$
0
0
Hi all,

Question is in the topic, instead of having one new workbooks with 6 sheets that contain the data from another workbook, it creates two - in the second one (say, Book2), sheet1, there is all data that is supposed to be in Sheet1 of Book1 (first newly created book). And Sheet1 in Book1 is empty...
I went through the code and have no idea why, could you help me with that?
Here is t


Code:

Sub jaktokvrwa()

  Dim TheNewWB As Workbook
    Set TheNewWB = Workbooks.Add

    ThisWorkbook. _
        Activate
    Sheets("A").Select
    Cells.Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    ThisWorkbook. _
        Activate
    Sheets("B").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Sheets("Sheet2").Select
    Cells.Select
    ActiveSheet.Paste
    ThisWorkbook. _
        Activate
    Sheets("C").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Sheets("Sheet3").Select
    Cells.Select
    ActiveSheet.Paste
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets.Add After:=Sheets(Sheets.Count)
    ThisWorkbook. _
        Activate
    Sheets("D").Select
    Range("Table24[#All]").Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Sheets("Sheet4").Select
    ActiveSheet.Paste
    ThisWorkbook. _
        Activate
    Sheets("E").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Sheets("Sheet5").Select
    Cells.Select
    ActiveSheet.Paste
    ThisWorkbook. _
        Activate
    Sheets("F").Select
    Range("C1:CC3").Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Sheets("Sheet6").Select
    Range("C1").Select
    ActiveSheet.Paste
    ThisWorkbook. _
        Activate
    Range("Table1[#All]").Select
    Application.CutCopyMode = False
    Selection.Copy
    TheNewWB.Activate
    Range("A4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False

End Sub

Thank you in advance for your help.

Viewing all articles
Browse latest Browse all 50110