VBA - replace cell value with sheet name for sheets beginning with a certain letter

athaung

New Member
Joined
Jan 10, 2014
Messages
23
Hi Everyone,

I've been reviewing various posts from this forum to piece together a solution, but was unsuccessful.

I have a workbook with a bunch of sheets and I am interested in the sheets that begin with the letter "P". Each of these sheets is named "P###" with #s ranging from 0-9 and not consecutively.

On each of these sheets, the various formulas link to the cell O37. I would like to replace the value in cell O37 with the name of the sheet "P###" for all sheets that begin with P.

Thanks in advance for any help!

Alison
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi and welcome to the forum. Try this...

Code:
[color=darkblue]Sub[/color] P_Sheets()
    [color=darkblue]Dim[/color] ws [color=darkblue]As[/color] Worksheet
    [color=darkblue]For[/color] [color=darkblue]Each[/color] ws [color=darkblue]In[/color] Worksheets
        [color=darkblue]If[/color] UCase(ws.Name) [color=darkblue]Like[/color] "P###" [color=darkblue]Then[/color]
            ws.Range("O37").Value = ws.Name
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,793
Members
451,589
Latest member
Harold14

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