Greetings! Tab name insert help

ritagail

New Member
Joined
Jul 28, 2009
Messages
24
Hi All -
I am creating a macro that loops through a file and reformats each worksheet then cuts and pastes the reformatted data into a Master sheet in another file. Since each file being reformatted has mulitple worksheets with differing tab names and file names I would like to insert the file name into cell b2 and the worksheet tab name into c2 so the data source is identifiable in the Master sheet. I cannot make this work. Any help would be greatly appreciated!
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Assuming you already have code that can activate the different worksheets in your workbooks, you might try:

Code:
Sub NamesAsVariables()
Dim sFileName, sTabName

'when the source file and tab are active while you are preparing to copy it
sFileName = ActiveWorkbook.Name
sTabName = ActiveWorkbook.ActiveSheet.Name

'after you have insterted it into your Master
Range("B2").Value = sFileName
Range("C2").Value = sTabName

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,273
Members
449,219
Latest member
daynle

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