Hello,
I am working on a macro to edit a fixed width text file. What I want my macro to do is loop through each line of the text file (copy and pasted into column A) and replace a value IF the value of "RecordType" = 1.
However, the line with the Replace function returns a mismatch error. Any ideas?
I am working on a macro to edit a fixed width text file. What I want my macro to do is loop through each line of the text file (copy and pasted into column A) and replace a value IF the value of "RecordType" = 1.
However, the line with the Replace function returns a mismatch error. Any ideas?
VBA Code:
Sub Test1()
Dim RecordType As Integer
Dim CurrentLine As String
FinalRow = Cells(65536, 1).End(xlUp).Row
For i = 1 To FinalRow
CurrentLine = Cells(i, 1).Value
RecordType = Mid(CurrentLine, 41, 1)
If RecordType = 1 Then
CurrentLine = Replace(CurrentLine, 122, 1, "E")
End If
Cells(i, 1).Value = CurrentLine
Next i
End Sub