?
Solved

Find and Replace with Excel VBA

Posted on 2015-02-06
3
Medium Priority
?
134 Views
Last Modified: 2016-02-10
Cells.Replace What:="1/2/1900", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Is it possible to modify the above VBA code to look for special range rather than the whole worksheet ?

Tks
0
Comment
Question by:AXISHK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 1200 total points
ID: 40593141
Yes you can do so by...

Lets say i want to check a1 to a10

range("A1:A10").Replace What:="1/2/1900", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Open in new window


In the first command cells means every cell in your worksheet.

Saurabh...
0
 
LVL 31

Assisted Solution

by:gowflow
gowflow earned 800 total points
ID: 40593175
correct and more

you have there Lookat:=xlPart
You have to be careful as you are searching for a date not a string which is something specific (unless this date comes in a string like: I went to the store on 1/2/1900 and got banned ..) but don't think so as this 1/2/1900 is more like a no date that shows as a date

So I would change the Lookat:=xlPart
by
Lookat:=xlwhole

and more but following does not apply to Replace but rather apply to Find but it is good mentioning as we are talking about the subject here.,

when you search for dates usually excel have a problem as the date you see is only a format of the real date that is a serial number so you may end up most of the time looking for a date with this instruction and not finding it although it is obvious for you that the date is there. All this to say that when you look for a date you are better off specifying in the argument Lookin xlformulas and not xlvalues as one would do in values.

So to sum it up for your instruction it would be safer to have it as follows for a range of say A1:A10
range("A1:A10").Replace What:="1/2/1900", Replacement:="", LookAt:=xlWhole, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
0
 

Author Closing Comment

by:AXISHK
ID: 40607134
Tks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question