Using VBA for Excel to automate spreadsheet search and replace functions
Posted on 2007-09-28
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:
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:
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?