afzalw
06-19-2013, 03:54 PM
I have this Macro which basicall reads the path from column A and search a string from Column B and Replace it with a String in Column C. It works and nothing wrong with it.
Now I want it to perform a bit differently. I want to know if its possible.
e.g It should search some string in Column A but don't replace it yet instead it should search for "1" from this position in the text file and replace "1" with string in column C.
Why: The reason I want to do that is that there are so many "1" in my text document and if I search "1" from the start it wont be a unique variable or I wont be able to replace the "1" I actually want to replae. But if it search for "1" after searching that string in Column A it would be the correct "1" I want to replace.
Thankyou
Here is my code:
LastRow = Sheets("Part B").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Sheets("Part B").Activate
With CreateObject("scripting.filesystemobject")
For i = 2 To LastRow 'assuming row 1 houses col heads
.createtextfile(Cells(i, 1)).write Replace(.opentextfile(Cells(i, 1)).ReadAll, Cells(i, 2), Cells(i, 7))
Next
End With
Now I want it to perform a bit differently. I want to know if its possible.
e.g It should search some string in Column A but don't replace it yet instead it should search for "1" from this position in the text file and replace "1" with string in column C.
Why: The reason I want to do that is that there are so many "1" in my text document and if I search "1" from the start it wont be a unique variable or I wont be able to replace the "1" I actually want to replae. But if it search for "1" after searching that string in Column A it would be the correct "1" I want to replace.
Thankyou
Here is my code:
LastRow = Sheets("Part B").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Sheets("Part B").Activate
With CreateObject("scripting.filesystemobject")
For i = 2 To LastRow 'assuming row 1 houses col heads
.createtextfile(Cells(i, 1)).write Replace(.opentextfile(Cells(i, 1)).ReadAll, Cells(i, 2), Cells(i, 7))
Next
End With