Help me edit code VBA!!!

Nguyen Anh Dung

Board Regular
Joined
Feb 28, 2020
Messages
180
Office Version
  1. 2016
Platform
  1. Windows
as code below:
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("GS013601.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")

'open file (immediate save not needed)
'Set wb = Workbooks.Open("D:\test_file\test\20200310_07_002_QTB_GS023662-gps.csv")
Set wb = Workbooks.Open(FolderPath & FileName)

'wb.SaveAs ("D:\test_file\test\20200310_07_002_QTB_GS023662.csv")
Set ws = wb.Sheets(1)
Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))

'add time columns
With rng.Offset(, 8)
.Formula = "=A2"
.Resize(, 2).NumberFormat = "YYYY-MM-DD hh:mm:ss"
.Value = .Value
.Offset(, 1).Value = .Value
End With

'add ID columns
ws.Range("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng.Formula = "=row()+1"
rng.Offset(, 1).Value = 1

'delete columns not required and insert headers
ws.Range("F:O").Delete Shift:=xlToLeft
ws.Range("A1:H1").Value = headers

'save and close
'wb.Save
wb.Close SaveChanges:=True 'False
End Sub

I have file test.csv with format as 1.jpg. i want copy file new test_heading.csv with format as 2.jpg. i have edit but only copy column lon and ele. help me!!!

column ID : Fill in the order automatically
trksegID default with value: 1
copy column Latitude->lat
copy column Longitude->lon
copy column Alevation->ele
copy column Heading->Heading
Date/Time ->Time with format "yyyy-mm-dd hh:mm:ss"
Time_N=time(7,0,0)+column time
 

Attachments

  • 1.jpg
    1.jpg
    115.4 KB · Views: 6
  • 2.jpg
    2.jpg
    59.2 KB · Views: 6

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,826
Messages
6,121,797
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top