Announcement

Collapse
No announcement yet.

Excel Macro

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Excel Macro

    To all the Excel masters, I'm trying to create a very simple macro but I've never used VBA before. I come from a background with lower level programming (hardware level up to C/C++) and from that point of view, VBA appears quite disgusting

    Here's what I'm trying to do:
    1) Automatically run the macro when the first cell changes
    2) Compare the value of the first cell to the second cell
    3) If the first cell value is less than the second cell value, update the second cell to this value

    I've had a bit of a look around on the net and had a couple of attempts myself with no results. Thanks for any help!

  • #2
    I dont use Excel macros so not sure if this will help but to do what you are after to a thrid field then that field would use the statement:

    =IF(A1<A2,A1,A2)

    I would imagine you could use a similar statement in a macro. Even if you populate A3 with the statement above and then copy A3 to A2 as you need to get around the circular reference.

    Comment


    • #3
      Worksheet Change Event: Run Excel Macros When a Cell Changes Or User Enters Data

      Comment


      • #4
        Originally posted by Kingy View Post
        I dont use Excel macros so not sure if this will help but to do what you are after to a thrid field then that field would use the statement:

        =IF(A1<A2,A1,A2)

        I would imagine you could use a similar statement in a macro. Even if you populate A3 with the statement above and then copy A3 to A2 as you need to get around the circular reference.
        I think it would be
        =IF(A1<A2,A2,A1)

        pretty sure the IF goes (logic statement,value if true, value if false)- you have it backwards.
        If cleanliness is next to godliness, why was jesus a dirty sandal-wearing beardo?

        Comment


        • #5
          Actually, you probably don't need to use a macro at all.
          You could just make the formula in A2
          =IF(A1>A2,A1,A2)
          dont have excel to test though, might not work due to having A2 in the formula for A2
          If cleanliness is next to godliness, why was jesus a dirty sandal-wearing beardo?

          Comment


          • #6
            Thanks for the replies. Yeah in the end I did not need a macro but I did need to enable iterative calculations. Without iterative calculations enabled Excel has issues with the circular referencing which was the initial problem.

            Comment


            • #7
              Originally posted by Semi View Post
              I think it would be
              =IF(A1<A2,A2,A1)

              pretty sure the IF goes (logic statement,value if true, value if false)- you have it backwards.
              No I don't.. I had that formulae in a third cell...

              But yeah I was not sure about the circular ref problem.. sounds like you can turn it off or something? I will have to have a look at that. Only just got the newer version of excel at work recently.

              Comment


              • #8
                yes you do. If its in a third cell it won't work, because it will only work for the first time you change it.
                If cleanliness is next to godliness, why was jesus a dirty sandal-wearing beardo?

                Comment

                Working...
                X