Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
As code VBA and picture below.
I have file_old column A have format: General (picture 1.jpg). When i copy to file new(picture 2.jpg),
I deleted duplicate values column F but still.
Link file: file_dinhkem.rar
I have file_old column A have format: General (picture 1.jpg). When i copy to file new(picture 2.jpg),
I deleted duplicate values column F but still.
Link file: file_dinhkem.rar
Code:
Sub ProcessMultipleFiles()
Dim NewFileName As String
Dim FileList As Variant, FilePath As Variant
Dim FolderPath As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = "C:\Users\dungna\Desktop\Vidu\"
FileList = Array("GS033690.csv")
For Each FilePath In FileList
FilePath = FolderPath & FilePath
If FSO.FileExists(FilePath) Then
NewFileName = FSO.GetBaseName(FilePath)
NewFileName = NewFileName & "_Heading.csv"
FSO.CopyFile FilePath, FolderPath & NewFileName, True
CSVAmend2 FolderPath, NewFileName
Else
MsgBox FilePath & " not found"
End If
Next FilePath
End Sub
Sub CSVAmend2(FolderPath As String, FileName As String)
Dim wb As Workbook, ws As Worksheet, rng As Range, headers As Variant
headers = Array("ID", "trksegID", "lat", "lon", "ele", "time", "time_N", "Heading")
Set wb = Workbooks.Open(FolderPath & FileName)
Set ws = wb.Sheets(1)
Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))
With rng.Offset(, 8)
.Formula = "=F2"
.Value = .Value
.Offset(, 8).Value = .Value
.Formula = "=A2"
.Value = .Value
.Offset(, 6).Value = .Value
.Offset(, 6).NumberFormat = "yyyy-mm-dd hh:mm:ss"
.Formula = "=A2+ TIME(7,0,0)"
.Value = .Value
.Offset(, 7).Value = .Value
.Offset(, 7).NumberFormat = "yyyy-mm-dd hh:mm:ss"
End With
ws.Range("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng.Formula = "=row()-1"
rng.Offset(, 1).Value = 1
ws.Range("F:O").Delete Shift:=xlToLeft
ws.Range("A1:H1").Value = headers
ActiveSheet.Range("A1:H50000").RemoveDuplicates Columns:=6, Header:=xlYes
wb.Close SaveChanges:=True 'False
End Sub