naming a report using replace

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
704
Office Version
  1. 365
Platform
  1. Windows
original file name
Expense Report lastname_firstname__ID Number_11-2024(Report Date 11.21.2024).xlsx
i need the new report based off this one to be a rename:
one attachment is called: Attachment2 = Replace(Attachment1, ".xlsx", ".pdf")
i now also need an attachment
replace BOTH the words "Expense Rport " with "Monthly Expense Report" and (Attachment1, ".xlsx", ".pdf")

how can i do that in one expression
thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Some specific examples would help to make it clearer. I think your solution is to nest Replace functions.
If the str = "dog cat fish bird" you could remove cat and fish with
Replace(Replace("dog cat fish bird"," cat","")," fish","")
If you want to replace a string with a string then your replacement string would be that string and not "".
HTH
 
Upvote 0
hi
i am sorry
can you use my file name and show me how you would do the nested reaplace:
Expense Report lastname_firstname__ID Number_11-2024(Report Date 11.21.2024).xlsx
I need the .xlsx replaced with PDF
and the words Expense report replaced with Monthly Expenses
thanks
 
Upvote 0
I'm assuming this is for use in vba code? Then wanting it done in one line doesn't really make sense unless it's just a learning exercise.
Replace(Replace("Expense Report lastname_firstname__ID Number_11-2024(Report Date 11.21.2024).xlsx","Expense Report","Monthly Expenses"),"xlsx","pdf")

The expression in code would be a lot shorter if the original string was assigned to a variable:
VBA Code:
Dim strReportName As String

strReportName = "Expense Report lastname_firstname__ID Number_11-2024(Report Date 11.21.2024).xlsx"
strReportName = Replace(Replace(strReportName,"Expense Report","Monthly Expenses"),"xlsx","pdf")
and even shorter if the Find and Replace strings were assigned to variables. However, the code itself would be longer - a small price to pay for being easier to read and follow.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,867
Members
452,678
Latest member
will_simmo

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