Pulling column value into each previously generated tab

A10hammond

New Member
Joined
May 8, 2019
Messages
4
I'm new to VBA in excel and I borrowed this code from a previous thread that has worked well. It takes each value from column B in my main tab and creates a named tab with the format of the CONTROL tab and hyperlinks it in the original tab. My problem is that each tab, although correctly named and linked, is filled with data from the CONTROL tab which I have set as the first value in the column. The tab is set up so that all the formulas reference cell A3 which references the value in cell B2 in the Holdings tab. Is there a way so that once the tabs are created, I can run another macro that has the first tab created have cell A3 reference B2 in the holdings tab, the second created tab has cell A3 referencing B3 and so on...? So that each tab is pulling data for the value the tab was named after.

This is the current code I have for excel 2016 on Windows 10:

Sub CreateAndNameWorksheets()
Dim c As Range

Application.ScreenUpdating = False
For Each c In Sheets("Holdings").Range("b2:b47")
Sheets("CONTROL").Copy After:=Sheets(Sheets.Count)
With c
ActiveSheet.Name = .Value
.Parent.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:= _
"'" & .Text & "'!A1", TextToDisplay:=.Text
End With
Next c
Application.ScreenUpdating = True
End Sub


Thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Sub CreateAndNameWorksheets()
    Dim c As Range
    
    Application.ScreenUpdating = False                      ' Don't show all the sheet creation process. Speeds things up
    For Each c In Sheets("Holdings").Range("b2:b47")        ' Loop through the names
        Sheets("CONTROL").Copy After:=Sheets(Sheets.Count)  ' Create a sheet for each name, based on CONTROL
        With c                                              ' the With / End With structure is  a shortcut to avoid having to type a objectname over and over
            ActiveSheet.Name = .Value                       ' Set the new sheet name to the value in the cell
            .Parent.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:= _
            "'" & .Text & "'!A1", TextToDisplay:=.Text      ' Link the cell to the new sheet
            ActiveSheet.Range("A3").Formula = "=Holdings!" & c.Address  ' Set the formula on the new sheet to the cell address
        End With
    Next c                                                  'loop to next cell in column B
    Application.ScreenUpdating = True
End Sub

Also next time use the code tags around any code you post. See below how to do that
 
Upvote 0

Forum statistics

Threads
1,223,165
Messages
6,170,449
Members
452,327
Latest member
kris9926

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