Consulting

Results 1 to 8 of 8

Thread: Dlete row

  1. #1

    Dlete row

    I will place the vba code in Report.xlsm
    my all files are located in same place
    Sheet name can be anything in both the files
    I need the vba code that will open both the file and do the process and save the file
    If cells of column C of data.csv matches with cells of column B of cars.xlsx then delete the entire row of cars.xlsx(here entire row means the cells which matches delete that entire row)
    and after the process close and save the file so that changes should be saved

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
        Dim cars As Range
        Dim csv As Range
        
        Set cars = Workbooks.Open(ThisWorkbook.Path & "\cars.xlsx") _
                    .Sheets(1).Cells(1).CurrentRegion
                    
        Set csv = Workbooks.Open(ThisWorkbook.Path & "\data.csv") _
                    .Sheets(1).Cells(1).CurrentRegion.Columns("C")
        
        cars.AdvancedFilter xlFilterInPlace, csv
        cars.Offset(1).EntireRow.Delete
        cars.Parent.ShowAllData
        
        cars.Parent.Parent.Close True
        csv.Parent.Parent.Close False
        
    End Sub

  3. #3
    mana sir plz have a relook to the code its not working
    i think u missed something in the code plz relook

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test2()
        Dim cars As Range
        Dim csv As Range
        
        Set cars = Workbooks.Open(ThisWorkbook.Path & "\cars.xlsx") _
                    .Sheets(1).Cells(1).CurrentRegion
                    
        Set csv = Workbooks.Open(ThisWorkbook.Path & "\data.csv") _
                    .Sheets(1).Cells(1).CurrentRegion.Columns("C")
        
        cars.Cells(2).Copy
        csv.Cells(1).Insert xlDown
        Set csv = csv.Offset(-1).Resize(csv.Cells.Count + 1)
        
        cars.AdvancedFilter xlFilterInPlace, csv
        cars.Offset(1).EntireRow.Delete
        cars.Parent.ShowAllData
        
        cars.Parent.Parent.Close True
        csv.Parent.Parent.Close False
        
    End Sub
    Last edited by mana; 08-31-2019 at 09:24 PM.

  5. #5
    Si plz see the sample file this code is unable to do the same
    I have attached the sampe file plz relook sir
    Attached Files Attached Files

  6. #6
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test2()
        Dim cars As Range
        Dim csv As Range
        
        Set cars = Workbooks.Open(ThisWorkbook.Path & "\1.xls") _
                    .Sheets(1).Cells(1).CurrentRegion
                    
        Set csv = Workbooks.Open(ThisWorkbook.Path & "\BasketOrder..csv") _
                    .Sheets(1).Cells(1).CurrentRegion.Columns("C")
        
        cars.Cells(2).Copy
        csv.Cells(1).Insert xlDown
        Set csv = csv.Offset(-1).Resize(csv.Cells.Count + 1)
        
        cars.AdvancedFilter xlFilterInPlace, csv
        cars.Offset(1).EntireRow.Delete
        cars.Parent.ShowAllData
        
        cars.Parent.Parent.Close True
        csv.Parent.Parent.Close False
        
    End Sub

  7. #7
    Thnx Alot Mana Sir for ur Great Support
    Problem Solved

  8. #8
    Mana Sir sorry to disturb u but it was not BasketOrder..csv it is BasketOrder..xlsx, in this post we dont have any csv file it is all xls file or xlsx file(1.xls is right and BasketOrder..xlsx is right), BasketOrder..csv is not there
    so plz relook sir in future this mistake will not be repeated

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •