Results 1 to 3 of 3

Thread: [RESOLVED] clear the data by vba macro

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    Resolved [RESOLVED] clear the data by vba macro

    Hi,
    Macro will be placed in macro.xlsm & book1.xlsx & Book2.xlsx are located at different place so the path of of both the files should be hardcoded in the macro

    If cells in column A of sheet1 of book2.xlsx matches with cells of column A of book1.xlsx then dont do anything & If it doesnt matches then clear all the data in that row of book2.xlsx from column B

    (clear all the data in that row of book2.xlsx from column B means from column B till the end of data we have to clear all the data in that unmatched cells in that row,we will not do anything with column A data)

    Thnx
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: clear the data by vba macro

    i am currently unable to open your samples, but based on your description
    Code:
    p1 = "c:\temp\"
    p2 = "C:\temp\"
    Set wb1 = Workbooks.Open(p1 & "book1.xlsx")
    Set wb2 = Workbooks.Open(p2 & "book2.xlsx")
    For Each cel In wb2.Sheets(1).Range("a:a")
        If IsEmpty(cel) Then Exit For  ' stop on empty cell
        Set fnd = wb1.Sheets(1).Range("a:a").Find(cel)
        If fnd Is Nothing Then cel.Offset(, 1).Resize(, Columns.Count - 1).Clear
    Next
    i will try to find a machine with a later version of excel, to test
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    Re: clear the data by vba macro

    Thnx Alot westconn1 Sir for helping me in solving this Problem Sir
    Have a Awesome Day Sir

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
  •  



Click Here to Expand Forum to Full Width