VBA Find & Replace

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,645
Office Version
  1. 365
Platform
  1. Windows
I am using the following to replace text strings in a selection but I need to use the Lookin:=xlValues but it doesn;t seem to like it
Code:
Selection.Replace What:="*H*", Replacement:="", LookAt:=xlPart, _
   SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
   ReplaceFormat:=False
Is there an option to look in values only as the default seems to be formulas?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
No there isn't.
The reason being that a value returned by a formula doesn't really exist, so if even if you changed it, the formula would return the original value when it next recalculated.
 
Upvote 0
Thanks Fluff

The selection I am looking in contains only values and there are no formulas at all.

After a bit of testing, sometimes this works and sometime it doesn't and I'm not sure why.
 
Upvote 0
That code should clear the contents of any cell that contains an h (regardless of case).
Is that what you are trying to do?
 
Upvote 0
In that case what is not working?
 
Upvote 0
the removing of any cell contents that contain a h doesn't always execute.

The line of code executes without an error but cells that contain a h are remaining.
 
Upvote 0
Odd, do you have any merged cells?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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