Results 1 to 5 of 5

Thread: EXCEL 2010: Why does macro record different to what I type?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Location
    Kent, England
    Posts
    713

    EXCEL 2010: Why does macro record different to what I type?

    Hi Guys,

    Hope someone can help.

    Basically I am recording / writing a macro to allow me to count all the rows before and after filter.

    so I start the Macro recording and type into cell A6
    Code:
    =COUNTIF((G2:G999999),"Void")
    The Macro then records:
    Code:
    ActiveCell.FormulaR1C1 = "=COUNTIF((R[-4]C[6]:R[999993]C[6]),""Void"")"
    Then I type into Cell A9
    Code:
    =COUNTIF((G2:G99999),"Purc")
    The Macro then records:
    Code:
    ActiveCell.FormulaR1C1 = "=COUNTIF((R[-7]C[6]:R[99990]C[6]),""Purc"")"
    So why is it that I choose to type in the above and its changed what I typed? why has it put the additional information in against what I typed?

    Can anyone shed any light on this? and does this mean in fact it is not go as far counting down to cell "999999"?
    Last edited by JayCR; Aug 4th, 2011 at 11:14 AM.
    "Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...

    Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: EXCEL 2010: Why does macro record different to what I type?

    Jay, there r 2 reference methods
    1. Absolute method = $A$1
    2. Relative method, it's from activecell, say for example if Activecell = B2 then reffer to A1 like this
    R[-1]C[-1]
    so the macro records using relative method, hope u got it.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: EXCEL 2010: Why does macro record different to what I type?

    What seenu_1st said. Since you are positioned on cell A6 (row 6, column 1) and the reference in your formula is G2 (row 2, column 7), excel macro recorder figures you want to reference 4 rows above and 6 columns to the right R[-4]C[6], leaving the reference relative. So if you apply it to another cell it will do exactly that, relative reference.

    A couple of things: It is in fact counting down to cell "G999999".
    If you have a fixed range type it as $G$2:$G$999999.
    Or you can go in and edit the code the macro wrote.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Location
    Kent, England
    Posts
    713

    Re: EXCEL 2010: Why does macro record different to what I type?

    Thanks Guys,

    So basically I can replace the relative method like for like what I have put in the cell?

    so replace
    Code:
    ActiveCell.FormulaR1C1 = "=COUNTIF((R[-4]C[6]:R[999993]C[6]),""Void"")"
    with
    =COUNTIF((G2:G999999),"Void")
    I have realised I can get rid of the G999999 just by replacing it with G:G to highlight the entire column...
    "Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...

    Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn

  5. #5
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: EXCEL 2010: Why does macro record different to what I type?

    Yes, you could. It is not necesary though as it is exactly the same, exept if you are posting the same formula in many different cells.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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