+ Reply to Thread
Results 1 to 22 of 22

If data matches then clear the data by vba

  1. #1
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    If data matches then clear the data by vba

    Hello Sir
    I am looking for a macro
    we have to look for only positive numbers in column S of sample1.xls & match column Y of sample1.xls with column B of sample2.xlsx
    if it matches then clear all the data in that row from column C of sample2.xlsx
    In the sample file
    3rd row data will be cleared from Column C(we will not clear the data of column A and Column B, clearing of the data will be start from Column C)
    Attached Files Attached Files

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Hi dumdumbum,

    Try the below code on a copy of your file

    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Thx Alot Nankw83 buti will put the macro in vba.xlsm,each file is in different path
    & Sorry Nankw83 for not providing that info to u in the earlier post
    Last edited by dumdumbum; 06-02-2020 at 10:33 AM.

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Do you mean the main file where you're reading the data from is different or the file where you want to delete the data from is different ?

  5. #5
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Yes all files are located in a different path
    And i will run the macro from vba.xlsm (Macro will be Placed in vba.xlsm file)

  6. #6
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Macro will be putted in this file which i have attached below
    Attached Files Attached Files

  7. #7
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Ok, I have added a prompt for you to select the file

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Sorry Nankw83, I don't need any prompt to select the file
    The macro should do this automatically , the reason for this is I have 3 macros that will run back to back ( I am looking to automate the same, No manual work will be done from my end)
    So request u plz have a relook Sir

  9. #9
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Quote Originally Posted by dumdumbum View Post
    Yes all files are located in a different path
    If the files are located in different path which you don't want hardcode in the VBA as provided in post #2 & you don't want to select the file yourself as provided in post #4, could you explain how this should be done ?

  10. #10
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    I got it , there is some misunderstanding
    Plz assume any location u want & I will edit it from myself as per my pc & file location but I don't need any pop up Sir

  11. #11
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Refer back to code provided in post #2 & change the below path to what you have in your PC

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Yes this I know but I am confused with sample2.xlsx, how I mention the path in the macro for the same, when I got ur post# 2 macro at that time I tried to edit it by myself & I got stuck in putting the location of sample2.xlsx so I asked u

  13. #13
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    I'm not certain that I follow … Simply open your Vba.xlsm‎ file & insert a new module (Alt + F11 --> Alt + I + M) the macro in post #2 & just change the file where you need to read data from

  14. #14
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Please Login or Register  to view this content.
    Instead of Active sheet I will put ws2
    And at the top I will put Dim Wb2 As workbook & ws2=wb2.sheet.item
    Am I right?

  15. #15
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Sure give me a sec I will let u know

  16. #16
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    If you need to specify the sheet of file Vba, you can do it like below

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Please Login or Register  to view this content.

    I used this nankw83 getting error with "expected end with" could u help me for the same

  18. #18
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    I've revised your code a little, try it now

    Please Login or Register  to view this content.
    Last edited by nankw83; 06-02-2020 at 11:45 AM. Reason: Small correction in the code

  19. #19
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    This code need some slight changes Bcoz we have to delete the data if column S of sample1.xls has positive numbers (But this macro delete the data if column S of sample1.xls has positive numbers & If column S has any alphabets also, it should not delete the data if column S has any alphabets)

    Plz run the Macro on sample file and notice the error Sir
    Last edited by dumdumbum; 06-02-2020 at 12:04 PM.

  20. #20
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    This is not an error, it was not asked for in your original post. Anyway, I've added one more condition as highlighted below

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    05-10-2020
    Location
    india
    MS-Off Ver
    2013
    Posts
    221

    Re: If data matches then clear the data by vba

    Awesome Nankw83, Thnx Alot for ur Great Support

  22. #22
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: If data matches then clear the data by vba

    Glad to help & thanks for the reps !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Comparing two data sets and finding matches or non matches
    By b0bertini in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-18-2017, 09:34 AM
  2. Replies: 4
    Last Post: 05-10-2015, 02:11 PM
  3. Comparing Data between sheets to find matches and no matches
    By tysont in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-26-2015, 03:07 PM
  4. Replies: 2
    Last Post: 09-15-2014, 09:58 AM
  5. Searching for matches from 2 columns and copying data from matches
    By Jesper Daelin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-01-2014, 10:49 AM
  6. Replies: 3
    Last Post: 01-19-2014, 12:27 PM
  7. Replies: 1
    Last Post: 06-21-2013, 04:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1