Add multiple sheets to code to copy column names and column sizes

oryngirl

New Member
Joined
May 13, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I don't know how to code. Just by going through some tutorials have I gotten to this point where I sort of understand what I'm trying to do, but I can't actually do it. I have a spreadsheet with 10 different tabs to represent the places I'm collecting data for. All of this data will be unique numbers, so I do not want to copy them from one tab/sheet to another. I do want to copy the names of the columns and the size of the columns through all the sheets. When I ran the code I kind of managed to cobble together last night, it worked but only for one sheet. I thought I was just missing the proper way to add multiple sheet names to the code. But apparently that is not it. Thanks for any help or guidance, it is appreciated.
 

Attachments

  • Excel VB code.png
    Excel VB code.png
    157.6 KB · Views: 7

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
VBA Code:
Sub CopyPasteSheet()
    'you can keep calling the sheet depending upon your sheet names
    Call CopyData("Sheet1", "Sheet2")
    Call CopyData("Sheet1", "Sheet3")
    Call CopyData("Sheet1", "Sheet4")
End Sub


Sub CopyData(sSourceSheet As String, sDestinationSheet As String)
    Sheets(sSourceSheet).Select
    Range("A1:O1").Copy
    Sheets(sDestinationSheet).Select
    Range("A1:O1").PasteSpecial xlPasteAll
    Columns("A:O").EntireColumn.AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

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