Wild card to find but not replace...

YeshyTiger

New Member
Joined
Oct 21, 2008
Messages
23
Good Morning,

I looked but didn't find another thread that addressed this question. If there is a post please direct me...

The question in short: Is it possible to use the wildcard function to find errors in an Excel workbook but then keeping the values of the wild card when replacing the error.

In long: I'm given a number of Excel data sheets to import regularly into another program but first I must check for the data to be in correct format. For example, data tagging is done in heirarchal order so a sample set might be : "A" then "A.1" and so on. Errors vary widely but 2 consistent problems are "A " and "A 1" . Because of this I cannot simply replace " " with "." I was hoping I could do a replacement code of find "* *" and replace with "*.*" In other words, keeping the values but replacing the error

Is this possible? Thank you
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I don't think you can do this with Find and Replace directly, but it could be done with a formula:

=SUBSTITUTE(TRIM(A1)," ",".")

then you could do a Copy, Paste Special Values and delete the original column if you like.

Or with VBA, which could do it in the same column

Code:
Sub test()
Dim c As Range
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    c = Replace(Application.WorksheetFunction.Trim(c), " ", ".")
Next
End Sub

I used the Worksheet function Trim rather than the VBA function Trim so that it would also remove excess spaces within the string.
 
Upvote 0
Thank you for the reply

I would prefer the VBA as I'm in Mid-development on a macro that will check and fix all common errors in all the .xls in a folder.

Will I need to end the Dim if I input this code into a larger macro?
 
Upvote 0
Ok, I think I understand. I'm sorry, I'm fairly new to Excel VBA and taking on a project probably a bit bigger than I am at the moment.

So using that code, could I also search for and eliminate other errors such as "A.." which should be "A" or "A..1" which should be "A.1"?
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,132
Members
449,098
Latest member
Doanvanhieu

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