VBA worksheet copy

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
i use the following line of code to copy one sheet from my workbook. how can i change this is include two sheets: "Budget" and "Summary"?

ThisWorkbook.Worksheets("Budget").Copy
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
what would i need to change this to to copy every sheet int he workbook?

Sheets(Array("Summary", "Budget")).Copy
 
Upvote 0
Hi,

Try:

Code:
    For Each sht In ActiveWorkbook.Sheets
        sht.Copy After:=Workbooks("Book2").Sheets(Sheets.Count)
    Next
 
Upvote 0
Another way:
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> exa()<br>    ThisWorkbook.Worksheets.Copy _<br>        After:=Workbooks("Book2.xls").Worksheets(Workbooks("Book2.xls").Worksheets.Count)<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
here is my complete code:
Code:
Sub ExportSheet()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Dim Folder As String
    Dim locationname As String
    Dim Response, pw
    Dim NewLogRow As Long
    Dim formula As String
    Dim NameValue As String
    Dim FinalName As String
    Dim XXX As String
   
    XXX = Format(Date, "[$-409]yyyymmdd;@")
    locationname = Sheets("Budget").Range("A3").Value
    Folder = "C:\Users\tphythian\Documents\Cost Tracking Exports"
    Worksheets("Budget").Visible = True
   
  [COLOR=red] Sheets(Array("Summary", "Budget")).Copy
[/COLOR]    With ActiveSheet.UsedRange
        .Value = .Value
    End With
    With ActiveWorkbook
        .SaveAs Folder & "\" & locationname & " - " & XXX & " - Export" & ".xlsx"
        .Close
    End With
    
                   
    MsgBox "Sheet has been exported and saved in " & "Cost Tracking Exports" & " folder!"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
[\code]
 
 
Neither of the codes provided works.  I am wanting to change the line in red to also include a sheet named "Transaction Log".  when this code adds all three sheets to the new workbook i want to also have the sheet "transaction log" hidden. hope someone can help.
 
Upvote 0
Hi,

Did you try this:

Sheets(Array("Summary", "Budget", "Transaction Log")).Copy
 
Upvote 0
well i had tried that yesterday and it was not working. i juswt tried it nowa nd it worked.

yesterday when i tried i was also trying to hid the sheet "Transaction log" once it is pasted into the new workbook. i guess i had that line creating soem issues.

how might i add hiding the sheet "transaction log" after it is pasted into the new workbook to my current code?
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top