Help with .Replace!

Raysoc

Board Regular
Joined
Feb 10, 2009
Messages
227
Googled and searched for the method properties and everything else, can not find a concrete answer!

I have the following code in my vba macro and I dont understand why its replacing any field with NA and not an EXACT match. What field is the check for exact match?

WSn.Columns("M").Replace What:="NA", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

The data has NA as some fields but not in #N/A format, just NA. So Nate would be delete, as well as NATHAN... not good..

Thanks!
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Change the parameter for LookAt from xlPart to xlWhole
 

Raysoc

Board Regular
Joined
Feb 10, 2009
Messages
227
grrr thanks! I could not find a primer that explained each setting for each method and what it does.. is there no such thing??
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Have you tried the help file? Also if you click on the keyword you want help with and hit F1, it will usually take you to the help topic you need.
 

Raysoc

Board Regular
Joined
Feb 10, 2009
Messages
227
I did try the help file on replace, it does not list the paramaters
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Sure it does:

Range.Replace Method
Returns a Boolean indicating characters in cells within the specified range. Using this method doesn’t change either the selection or the active cell.
Syntax

expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat)

expression A variable that represents a Range object.

Parameters

Name Required/Optional Data Type Description
What Required Variant The string you want Microsoft Excel to search for.
Replacement Required Variant The replacement string.
LookAt Optional Variant Can be one of the following XlLookAt constants: xlWhole or xlPart.
SearchOrder Optional Variant Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
MatchCase Optional Variant True to make the search case sensitive.
MatchByte Optional Variant You can use this argument only if you’ve selected or installed double-byte language support in Microsoft Excel. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.
SearchFormat Optional Variant The search format for the method.
ReplaceFormat Optional Variant The replace format for the method.

Return Value
Boolean

Remarks


The settings for LookAt, SearchOrder, MatchCase, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.


Example


This example replaces every occurrence of the trigonometric function SIN with the function COS. The replacement range is column A on Sheet1.

Visual Basic for Applications
Worksheets("Sheet1").Columns("A").Replace _
What:="SIN", Replacement:="COS", _
SearchOrder:=xlByColumns, MatchCase:=True

xlLookAt and xlSearchOrder are hyperlinks which explain those options further
 

Watch MrExcel Video

Forum statistics

Threads
1,122,842
Messages
5,598,396
Members
414,235
Latest member
sucosama

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
Top