help me in case of deleting duplicate values with VBA!!!

Nguyen Anh Dung

Board Regular
Joined
Feb 28, 2020
Messages
180
Office Version
  1. 2016
Platform
  1. 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


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
 

Attachments

  • 2.jpg
    2.jpg
    233.1 KB · Views: 7
  • 1.jpg
    1.jpg
    170 KB · Views: 8

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Your requirement is not clear. Your data has many columns, and it sounds like you want to exclude lots of data readings, based on duplication occuring in one column? Are the non-time columns not important at all? By the way, I can't open RAR files, and I doubt many people on here could.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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