Replace A Character Within A String

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Code:
cfn = ws_vh.range("B23")

cfn = "May-24 (Fri) schedule_1.xlsx"

I am looking for a vba solution to replace the "_1" with "_2" in this string.
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
k9 = InStr(ws_vh.Range("B23"), "_") + 1
cof = Application.WorksheetFunction.Replace(ws_vh.Range("B23"), k9, 1, "2")
 
Last edited:
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...ror-trying-to-set-a-workbook.html#post5124066

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Not really the same question Fluff. One was about the reason for an error when trying to set a workbook. This one was about how to replace a character in a string. Same macro, different problem. One problem cropped up after the first was solved.
 
Last edited:
Upvote 0
I would have to disagree, bth were about the same thing, ie changing the last value from 1 to 2.
 
Upvote 0
In the other post, the value had already been figured out how to change it to 2.
After the file name was changed, I needed a solution as to why I couldn't set that new name to ws_nwb.

Different.
 
Upvote 0

Forum statistics

Threads
1,223,955
Messages
6,175,605
Members
452,660
Latest member
Zatman

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