Excel VBA: Add Suffix to Specific Worksheets

MrNovice1

New Member
Joined
Mar 9, 2019
Messages
2
Hello All,

I am just beginning to explore Excel VBA, and have written minor macros but am in need of assistance. I have an Excel document with 6 worksheets, 3 which contain the word "Detail" as part of their names. I need to create a macro that will add the suffix "-Final" to the worksheets that contain the word. I also need the macro to add a suffix "-Void" to the worksheets that don't contain the word. I know the macro will have to use wildcards to search and I am clueless with this …. please help!!! Any help will be greatly appreciated, as some of my files have any worksheets, and manually doing this is exhausting.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
this should do it

Code:
Sub t()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
    If InStr(sh.Name, "Detail") > 0 Then
        sh.Name = sh.Name & "-Final"
    Else
        sh.Name = sh.Name & "-Void"
    End If
Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
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