Workbook with many Sheets - Need to dynamically create a column and insert sheet name into every row of all sheets

jholly1984

New Member
Joined
Sep 29, 2020
Messages
15
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Hi everyone,

I am having an excel automation issue that I am hoping someone can help with.

Problem: Being able to automatically add a column and fill the column in with its associated sheet name for multiple sheets at the same time.

Context:
The workbook contains a large number of sheets named by category:

Tab 1 = Category 1
Tab 2 = Category 2
Tab 3 = Category 3
Tab 4+ = Etc.

We want to be able to add a column for every sheet at one time that pulls the tab name into every row as an identifier.

Current State:

Sheet Name 1 = Laptops
Columns = Keyword, Rank, URL

Sheet Names 2+ = Category Name 2+
Columns = Keyword, Rank, URL

Expected Output:

Sheet Name 1 = Laptops
Columns = Keyword, Rank, URL, Category/Sheet Name

We are hoping to be able to insert a macros or formula that will plug the sheet name in across 100+ sheets vs having to do it manually.

Thank you for your time.
 
Last edited by a moderator:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I have this function for being able to dynamically plug the sheet name into a cell:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)

What we can't figure out is:

a) How to do this for an entire column dynamically
b) How to do this for an entire column across a large number of sheets dynamically
 
Upvote 0
I'm not sure if I understood correctly, but try this macro:
VBA Code:
Sub AddSheetName()
    Application.ScreenUpdating = False
    Dim LastRow As Long, ws As Worksheet
    For Each ws In Sheets
        With ws
            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Range("D1") = "Sheet Name"
            .Range("D2:D" & LastRow) = ws.Name
        End With
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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