Insert Sheet Name for each cell in range

spencerCCole

New Member
Joined
Apr 30, 2019
Messages
1
Hello,

I need help creating some code that will automatically fill in each row with the sheet name. I receive a workbook weekly, with about 50 different sheets of data I need to analyze. Doing this manually is very time consuming.

Ex:
Sheet1 is Named KEL01, i need KEL01 filled into every cell in Column A, down to the last row with data in it.
Sheet2 is Named KEL02, i need KEL01 filled into every cell in Column A, down to the last row with data in it.

and so on.

Any suggestions would help!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Should VBA loop though EVERY sheet in the workbook adding the sheet name in column A
Does column A require to be inserted (or is it already there) ?
Which column contains data in every row ?
Will the VBA reside in a different workbook ?

The basic code (untested) is below. Modify to insert column A, set the correct workbook etc
Code:
Dim Ws as WorkSheet, Wb As WorkBook, r As Long
Set Wb = ?..?
For Each Ws In Wb.Sheets
  r = Ws.Cells(Rows.Count,"B").End(xlUp).Row
  Ws.Range("A2:A" & r).Value = Ws.Name
  Ws.Range("A1") = "Sheet"
Next Ws
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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