Sub test_Variant2()
Dim fn As String, txt As String, x, y, n As Long
Dim myCols, colRef, i As Long, ii As Long
Dim strPath As String, strFile As String
Dim d As Date, dLatest As Date
strPath = Environ$("UserProfile") & Application.PathSeparator
strFile = Dir(strPath & "*.csv", vbNormal)
Do While Len(strFile) > 0
d = FileDateTime(strPath & strFile)
If d > dLatest Then
fn = strFile
dLatest = d
End If
strFile = Dir
Loop
' fn = Application.GetOpenFilename("CSVFies,*.csv")
' If fn = "False" Then Exit Sub
myCols = Array("FEATURE CODE", "Point_ID", "Easting", "Northing", "ELEVATION", "Remark1")
x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll, vbCrLf)
colRef = Filter(WorksheetFunction.IfError(Application.Match(myCols, Split(x(0), ","), 0), False), False, 0)
ReDim a(1 To UBound(x) + 1, 1 To UBound(colRef) + 1)
For i = 0 To UBound(x)
If x(i) <> "" Then
y = Split(x(i), ","): n = n + 1
For ii = 0 To UBound(colRef)
a(i + 1, ii + 1) = y(colRef(ii) - 1)
Next
End If
Next
Range("a2").Resize(n, UBound(a, 2)).Value = a
End Sub
Bookmarks