The issue continues this topic and is associated with my earlier post. The code should deal with .csv files changing cells' values and interior color. It does its job, but after saving .txt as .csv I end up with something that looks like the source file - no changes visible.
I thought of using dictionaries, but to my understanding, to do so, I had to edit the newly saved .csv, which is exactly what I am trying to avoid in the below code. Does anyone have an idea how to have the changes saved?
Option Explicit
Sub fixCellsValue()
Dim wrk As Workbook
Dim Sh As Worksheet
Dim SourceFolder As String, Path As String, TmpFlName As String
Dim i As Long, lastrow As Long
SourceFolder = ThisWorkbook.Path & "\source"
'creating temporary .txt file
If Dir(SourceFolder & "SomeFile.*") <> "" Then
If InStr(1, Dir(SourceFolder & "SomeFile.*"), ".csv") Then
TmpFlName = SourceFolder & "\TmpCsv.txt"
If Dir(TmpFlName) <> "" Then Kill TmpFlName
FileCopy SourceFolder & "SomeFile.csv", TmpFlName
Workbooks.OpenText Filename:=TmpFlName, origin:= _
1250, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, TrailingMinusNumbers:=True, Local:=False
Set wrk = Application.Workbooks("TmpCsv.txt")
Set Sh = wrk.Worksheets(1)
lastrow = Sh.Cells(Sh.Rows.Count, "A").End(xlUp).row
'implementing changes to the temporary .txt file
For i = 2 To lastrow
If Len(Sh.Cells(i, 5)) > 10 Then
Sh.Cells(i, 5) = Left$(Sh.Cells(i, 5).Value, 10)
Sh.Cells(i, 5).Interior.ColorIndex = 6
End If
Next i
End If
End If
'saving as .csv file and deleting .txt file
If InStr(1, wrk.Name, "TmpCsv.txt") Then
wrk.SaveAs Filename:=Dir(SourceFolder & "SomeFile.*"), FileFormat:=xlCSV, Local:=True
wrk.Close Savechanges:=True
Kill TmpFlName
End If
End Sub