Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel macros

  • 17-06-2004 1:52pm
    #1
    Closed Accounts Posts: 3,322 ✭✭✭


    Im trying to write a macro in excel that compares every field in 1 column of the first sheet, with every field in 1 column of the second sheet and if there is an entry in 1 sheet that doesn't exist in another sheet, print out that entry. I have it done in C++ after exporting the data as a text file but I need to write a macro to do the same thing.
    Any links to some good tutorials or anything?
    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Pretty much what I would do is this. We take that the workbook has the 3 default spreadsheets: Sheet1, Sheet2 and Sheet3.

    So you're comparing Column A on Sheet1 to Column B on Sheet2 and the results are in Column A sheet3, to do this put the following Formula into Column A Cell1 on Sheet3 (This needs further work of its to be bi-directional).
    =IF(Sheet1!A1<>Sheet2!A1, Sheet1!A2, "")
    

    if the values are not equal (Sheet1!A1<>Sheet2!A1) then value_if_true is placed in that cell, in this case the value of Sheet1!A2 and if the value is false then "" is placed in the cell. Lookup 'If worksheet function' in the Excel help file.

    Now you just have to placed this formula in all the appropriate cells, you can do this in a macro as follows.
    Public Sub MacroForRepli
    
    dim sFormula as string 
    dim l as Long
    
       sFormula = "=IF(Sheet1!A1<>Sheet2!A1, Sheet1!A2, "")"
    
       ActiveWorkboox.Worksheets("Sheet3").Activate
       Range("A1").Activate
       ActiveCell.Value = sFormula 
    
       for l = 1 to 500 '// Nice round figure, use your own here.
          ActiveCell.OffSet(1,0).Activate '// This selects the next cell down
          ActiveCell.Value = sFormula 
      next 
    
    End Sub
    

    I haven't tested this code so take it as an approximation. Knowing vb helps a lot with this, I don't have any good links for you. I'm pretty much self taught.


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    http://mvps.org/dmcritchie/excel/excel.htm
    http://www.j-walk.com/ss/excel/tips/index.htm

    I've a whole bunch of links if you want me to email them to you.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Could you pm them to me to Ricardo?


Advertisement