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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,215,181
Messages
6,123,508
Members
449,101
Latest member
mgro123

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