Range Replace? Correct syntax?

passinthru

Board Regular
Joined
Jun 16, 2003
Messages
185
In an old thread, I found what seems to be the solution I'm looking for, but I'm having trouble with the syntax. Member doofusboy suggested:

Range(your_cell_address_here).Value = Replace(Replace(Replace(Replace(Range(your_cell_address_here).Value," ","_"),"-",""),"(",""),")","")

This seemed to work for the OP on that thread.


However, when I try it in a macro, I get a "Type Mismatch" error. :confused:

Here's my code:

Range("A1:A2000").Value = Replace(Replace(Range("A1:A2000").Value, "ms TTL", "|ms TTL"), "time=", "time=|")


This is the first line of code, and it croaks right there. No joy.Can someone tell me what obvious mistake I've made? :stickouttounge:

The regular Search & Replace is not reliable, for reasons I mention in the original thread. :(

 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
' dummy find to reset retained state
Range("A1").Find What:="Texas", _
                 MatchCase:=False, _
                 MatchByte:=False, _
                 SearchFormat:=False
 
Range("A1:A2000").Replace What:="ms TTL", _
                          Replacement:="|ms TTL", _
                          LookAt:=xlPart, _
                          ReplaceFormat:=False
Range("A1:A2000").Replace What:="time=", _
                          Replacement:="time=|", _
                          LookAt:=xlPart, _
                          ReplaceFormat:=False
 
Upvote 0
Dot verks! :)

Thank you! :bow:


I like this method better, too. Multiple nesting can get confusing.


Bit of a kludge that the required setting isn't available in the search/replace code, isn't it?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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