VBA Code that Copies a Tab and Find/Replace Formulas

kirklj

New Member
Joined
Jan 10, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello XLers!

I need help with constructing a relatively simple macro. I've built a workbook containing this table:

Company NameDirectory Path
Company BPath B
Company CPath C
Company DPath D
Company EPath E
Company FPath F
Company GPath G

The macro should be able to perform the following:
  1. Copy template tab "Company A", and then place the copied tab after "Company A".
  2. Rename the copied tab to "Company B" and then Find/Replace Directory Path A with Path B.
  3. Repeat step 1 but place the copied tab after "Company B". **
  4. Repeat step 2, but with Company C.
  5. Continue to loop through the Company Name - Directory Path table indefinitely until each company is represented with its own tab.
**NOTE: For each subsequent copy of template tab "Company A", the copied tab will need to go to the "back of the line" so that when the macro concludes, the tab order is Company A, Company B, Company C, etc.

Thanks in advance for your help, XLers!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Where should Directory Path info go in Column B or C sheet?
The info coming into the "Company A" sheet is done so via a data link to an outside source. That said, by changing the directory path (from Company A's data source to Company B's, for example) the underlying information for a specific company will then populate the template. I hope this makes sense.
 
Upvote 0
The info coming into the "Company A" sheet is done so via a data link to an outside source. That said, by changing the directory path (from Company A's data source to Company B's, for example) the underlying information for a specific company will then populate the template. I hope this makes sense.
Where should Directory Path info go in Column B or C sheet?
Since my workbook is currently influx, my plan was to use a named range to refer to the directory path info.
 
Upvote 0
Unfotunately, I didn't get it.. Fİnd my example below. I hope you can modify it according to your need.
Let's say you have:
1673446793881.png

1673446816311.png

Code:
VBA Code:
Sub myFunction()
  Dim lRow As Long, newSheet As Worksheet
  lRow = Cells(Rows.Count, 1).End(xlUp).Row
  
  For i = 2 To lRow
    Worksheets("Company A").Copy After:=Sheets(Sheets.Count)
    Set newSheet = ActiveSheet
    newSheet.Name = Cells(i, 1).Value
    newSheet.Cells(2, 1).Value = Cells(i, 1).Value
    newSheet.Cells(2, 2).Value = Cells(i, 2).Value
  Next
End Sub
You will have:
1673447326936.png
 
Upvote 0
Unfotunately, I didn't get it.. Fİnd my example below. I hope you can modify it according to your need.
Let's say you have:
View attachment 82521
View attachment 82523
Code:
VBA Code:
Sub myFunction()
  Dim lRow As Long, newSheet As Worksheet
  lRow = Cells(Rows.Count, 1).End(xlUp).Row
 
  For i = 2 To lRow
    Worksheets("Company A").Copy After:=Sheets(Sheets.Count)
    Set newSheet = ActiveSheet
    newSheet.Name = Cells(i, 1).Value
    newSheet.Cells(2, 1).Value = Cells(i, 1).Value
    newSheet.Cells(2, 2).Value = Cells(i, 2).Value
  Next
End Sub
You will have:
View attachment 82526
Thanks for you guidance!
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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