PDA

View Full Version : Find and replace lines in csv files with a excel sheet



trez
09-07-2015, 03:38 PM
I wanted to know if this is possible. I want to use a macro to find and replace lines in a directory of csv files. I would like to put the old string in column A and the replacement string in column b. Please let me know what additional information you need. Also attached an example.



14341

mancubus
09-08-2015, 03:04 PM
welcome to the forum.

upload two or three csv files. you can zip them before uploading.
manually fill in the blank workbook in the first post with desired output and upload it again.

trez
09-13-2015, 11:42 AM
Sorry for the delay. I have attached the files hopefully this helps. I would like to be able to tell the string it needs to look for and replace also the ability to delete a line from a directory of CSVs.14378143791438014381

mancubus
09-14-2015, 01:09 AM
from the desired output, it is apparent that you want to process the first lines of csv files only.
otherwise you would provide all lines from all sample files as desired output.

your sample1:
old : Field,245,10,700,ROSS,Tim,594404309,1MEC,WH0GT0,,49PK04015,,11/20/2015,1
new: Field,245,10,700,ROSS,Tim,594404309,1MEC,WH1GT0,,49PK04015,,11/20/2015,1

your sample2:
old : Camp,246,1,132,Smith,John,1202020,4ME3,W4QAA,,B06PM24601,,1/10/2016,0
new: Camp,246,1,132,mike,John,1202020,4ME3,W4QAA,,B06PM24601,,1/10/2016,0

now VBA needs a rule to replace a substring with another substring.
regarding your example, i conclude:
1 open all csv files in a subfolder,
2 write first lines in column B
3 look in this this value (1) WH0GT0 and (2) Smith
4a (if found) replace WH0GT0 with WH1GT0
4b (if found) replace Smith with mike (while S is upper case m must be lower case)
5 write replaces value to column C
6 insert order number in column A


:dunno

@trez
i am too busy this week but i took time to Show how a request in help forums should be explained.