Advertisement

09.28.2007 at 01:12PM PDT, ID: 22860459
[x]
Attachment Details

Using VBA for Excel to automate spreadsheet search and replace functions

Asked by netwrked in Spreadsheet Software, Visual Basic Programming, Microsoft Excel Spreadsheet Software

Tags: , , , ,

I am looking for a better method to do search and replace for data on an Excel VBA file import conversion application.  Currently, we have a subroutine that performs 4,500 search and replaces.  This subroutine runs for each record imported.   Generally, there is only one replacement per record.

The import file is a CSV delimited file, but it is not that easy.  It has a record structure like:

12,1234,43445,3435,454,45,,4322,65656,3423432,23232,23,23,23,232325,5,67,6,676
88,43234,344,434,4,AAA=#8989894,324,32,432,4,43,24,324,324,324,36,7,87,9,88,755
88,2313,,454,34,24,324,,6,6,87,78,453,4,43,43,44\TC

Currently, I import each line, looking for the #12 at the beginning.  I then grab the next line and look for the AAA=#898989.   The 898989 gets replaced with 1234344369765.  It then reads the next line, sees the \TC and knows that is the end of the record.  This then repeats.

What I would like to do is just open up the file as a block of text, not in columns like it opens now.  Then, I would like to be able and put the 4,500 criteria in a table on a separate spreadsheet.  First column would contain data to search for and the second column would contain the replacement data.  Then, run a search and replace function that reads the first line of the criteria table, use that entry for the search/replace, go to the next line in the criteria table, etc.

It would go something like this:

Search             Replace
8989894         1234344369765
1234121         9579842478944
3374622         4509878348240

Routine seaches entire document for 8989894 and replaces all instances with 1234344369765.  then, routine seaches entire document for 1234121 and replaces all instances with 9579842478944 and so on.  Is this doable?

Thanks,

Joe


Start Free Trial
[+][-]09.28.2007 at 01:43PM PDT, ID: 19981649

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.28.2007 at 06:27PM PDT, ID: 19982660

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.01.2007 at 08:29AM PDT, ID: 19991387

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Spreadsheet Software, Visual Basic Programming, Microsoft Excel Spreadsheet Software
Tags: vba, excel, replace, using, search
Sign Up Now!
Solution Provided By: LoNeRaVeR9
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.02.2007 at 06:52AM PDT, ID: 19998567

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628