Ask Experts Questions for FREE Help !
Ask
    cool143's Avatar
    cool143 Posts: 7, Reputation: 1
    New Member
     
    #1

    Sep 23, 2009, 02:05 AM
    Macro application
    Hi,

    I wanted to create an macro application.

    In 1st sheet, I have 5 columns and 1000 rows (may vary).
    In 2nd sheet, I have 5 columns and 1000 rows (may vary).

    Now I wanted to compare 1st sheet with 2nd sheet (Only one column)

    If cells in sheet1 is not equal to sheet2, copy that entire row to new sheet3.

    Please anyone help...
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Sep 23, 2009, 08:41 AM

    1) Is 1st sheet named Sheet1?
    2) Is 2nd sheet named Sheet2?
    3) Is 3rd sheet named Sheet3?

    4) You want to compare ALL 5 cells in row1 on sheet1 to ALL 5 cells in row1 of sheet2? Then row2 on sheet1 to row2 on sheet2?

    Or are the 5 cells on Sheet1 Row1 possibly found together somewhere other than row1 on sheet2? Meaning we need to check the entire dataset on sheet2?

    5) Are there headers at the top of your 5 cells?

    If you actually posted a sample sheet, this would be very easy to write. Click GO ADVANCED and use the paperclip icon to post up your workbook.
    cool143's Avatar
    cool143 Posts: 7, Reputation: 1
    New Member
     
    #3

    Sep 23, 2009, 08:09 PM


    Hi

    Please find the sample spread sheet.

    1. I wanted to compare column D (Sheet1) with Column A(sheet2). If the cell is not matching, I wanted to copy the entire row of Sheet1 to sheet3.
    2. When pasting the row in sheet3, I want some columns.
    For eg: From sheet1, Column D,A,C ( that I highlighted in attached sheet - Sheet3)

    Please help on this...
    Attached Files
  1. File Type: xls Book1.xls (19.0 KB, 157 views)
  2. JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #4

    Sep 24, 2009, 12:45 AM

    This little macro presumes column AA in sheet 1 is empty for a "filter" to be applied. It will put a formula in that column, then copy the rows that are "x", then remove the helper column.

    Hopefully this will be faster than looping through the rows one at a time and testing the 3 criteria that way.

    Give it a whirl:
    Code:
    Option Explicit
    
    Sub Differences()
    'JBeaucaire  (9/24/2009)
    Dim LR As Long
    Application.ScreenUpdating = False
    
    Sheets("Sheet1").Activate
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    Range("AA1") = "Key"
    Range("AA2:AA" & LR).FormulaR1C1 = _
        "=IF(ISNUMBER(MATCH(RC4&""-""&RC1&""-""&RC2&""-""&RC3, INDEX(Sheet2!R2C1:R100C1&""-""&Sheet2!R2C2:R100C2&""-""&Sheet2!R2C3:R100C3&""-""&Sheet2!R2C4:R100C4,0), 0)),"""",""x"")"
    
    Range("AA1").AutoFilter
    Range("AA1").AutoFilter Field:=1, Criteria1:="x"
    
    Sheets("Sheet3").Cells.Clear
    Range("D1:D" & LR).Copy Sheets("Sheet3").Range("A1")
    Range("A1:A" & LR).Copy Sheets("Sheet3").Range("B1")
    Range("C1:C" & LR).Copy Sheets("Sheet3").Range("C1")
    Range("AA1").AutoFilter
    Range("AA1:AA" & LR).ClearContents
    Sheets("Sheet3").Activate
    
    Application.ScreenUpdating = True
    End Sub
    How to use the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Is ITIN application and tax refund application different? [ 2 Answers ]

I applied for ITIN with my tax return this year. Do I need to apply again for my tax return separately or tax return application with ITIN is sufficient?

Macro help [ 3 Answers ]

Hi all, I am currently working with a dataset where the data in column A is empty until a user enters a rank (i.e. like ranking grades in ascending order). Currently the macro takes the number and moves the row entry to the top by assuming that the rank is to be the highest rank (it then takes...

If statement macro [ 10 Answers ]

Hello , I have an excel macro to take data from one spreadsheet and format in a partciular method. Now I want to add an if statement like I have an excel formula that works but I need it put into the macro. The formula is: if(AA21="USD", "6YB", "6YA") Help Thanks

Pending appeal of your old application for benefits, can you file new application? [ 1 Answers ]

Pending appeal of your old application for benefits, can you file new application?

Application to accelerate & application to revoke [ 14 Answers ]

Application to accelerate and application to revoke? What are the different. :cool:


View more questions Search