Find and Replace Macro for Excel (If x exists then replace y with x) - For Microsoft Excel

churchizactiive

New Member
Joined
Jan 24, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I created a macro in excel that runs a specific report for me and it works beautifully. I want to upgrade this macro to replace the "Insert Association Name" with the name of the specific community. That community name can be found in every report in the details column. For this one in particular it is named Apple Tree as described in the details column.

Essentially I'm looking for this new macro to see if "x community" exists then replace Insert Association Name with "x community". I would like the macro to run the instance for every community in my portfolio just incase when i run this report it's a different community name located within the details column

It would be an added bonus for the macro to include a print to pdf and save under a specific name too.

FYI - The Insert Association Name is in the Header so I don't know if that will make a difference. I tried the find and replace normally to replace Insert Association Name with Apple Tree and it didn't work.
Image
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,

maybe this can do for a start:

VBA Code:
Public Sub MrE_1227933_170181C()
' https://www.mrexcel.com/board/threads/find-and-replace-macro-for-excel-if-x-exists-then-replace-y-with-x-for-microsoft-excel.1227933/
' Static concept, only DataRange in picture - no xl2BB
  Dim sReplacment     As String
  
  Const cstrWHAT      As String = "Insert Association Name"
  Const cstrCOL       As String = "F"
  
  With ActiveSheet
    'address to be chamged to suit
    sReplacment = .Cells(4, cstrCOL).Value
    
    With .PageSetup
      ' Substitute Header/Footer values
      .LeftHeader = Application.WorksheetFunction.Substitute( _
                    .LeftHeader, cstrWHAT, sReplacment)
      .CenterHeader = Application.WorksheetFunction.Substitute( _
                      .CenterHeader, cstrWHAT, sReplacment)
      .RightHeader = Application.WorksheetFunction.Substitute( _
                     .RightHeader, cstrWHAT, sReplacment)
      .LeftFooter = Application.WorksheetFunction.Substitute( _
                    .LeftFooter, cstrWHAT, sReplacment)
      .CenterFooter = Application.WorksheetFunction.Substitute( _
                      .CenterFooter, cstrWHAT, sReplacment)
      .RightFooter = Application.WorksheetFunction.Substitute( _
                     .RightFooter, cstrWHAT, sReplacment)
    End With
  End With
End Sub

Are you talking about one sheet, a couple of sheets, a workbook to save? And where: at a given place, in folder of workbook with code, any folder to be chosen by user?

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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