Consulting

Results 1 to 7 of 7

Thread: VBA: Mixing Relative & Absolute References

  1. #1
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location

    VBA: Mixing Relative & Absolute References

    Hi,
    I have an absolute reference formula that I need to change to always go to the second row ie. A2 G2 W2 wherever it is used instead in this example 67 above.

        ActiveCell.FormulaR1C1 = _        "=SUMPRODUCT(COUNTIF(R[-67]C:R[-1]C,{""HBA1"";""HBA2"";""HBA3"";""HBA4"";""HBA5"";""HBA6"";""HBA7"";""HBA8"";""HBA9"";""HBAF"";""VANT1"";""VANT2"";""VANT3"";""VANT4"";""VANT5"";""BEAUA"";""BEAUM"";""BEAUX""}&""""))"
    Any help is always appreciated.

    I am working with Windows Home Premium version 6.1.7601 SP 1 Build 7601and Excel version 14.0.6123.5001 (32 bit)
    Regards, Peter.

  2. #2
    VBAX Contributor D_Marcel's Avatar
    Joined
    Feb 2012
    Location
    Tokyo
    Posts
    117
    Location
    Hi Peter. You may use this:

    [VBA]Cells(2, ActiveCell.Column).Value = "=SUMPRODUCT(COUNTIF(R[-1]C:R[-1]C,{""HBA1"";""HBA2"";""HBA3"";""HBA4"";""HBA5"";""HBA6"";""HBA7"";""HBA8""; ""HBA9"";""HBAF"";""VANT1"";""VANT2"";""VANT3"";""VANT4"";""VANT5"";""BEAUA "";""BEAUM"";""BEAUX""}&""""))"[/VBA]

  3. #3
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi D_Marcel,
    Thank you for your reply and code. I'm sorry to say I can't get it to work. Please see attachedTest.xlsx.xlsm
    Regards, Peter.

  4. #4
    VBAX Contributor D_Marcel's Avatar
    Joined
    Feb 2012
    Location
    Tokyo
    Posts
    117
    Location
    Hi Peter,

    You're welcome! If I understood your purpose, you need to insert this function always in the second row and in the current column, right? If you're selecting the cell G187, for example, the function should be inserted at cell G2.

    Is that right?

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I think you mean:
    [vba]ActiveCell.FormulaR1C1 = _
    "=SUMPRODUCT(COUNTIF(R2C:R[-1]C,{""HBA1"";""HBA2"";""HBA3"";""HBA4"";""HBA5"";""HBA6"";""HBA7"";""HBA8""; ""HBA9"";""HBAF"";""VANT1"";""VANT2"";""VANT3"";""VANT4"";""VANT5"";""BEAUA "";""BEAUM"";""BEAUX""}&""""))"
    [/vba]
    Be as you wish to seem

  6. #6
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    HI Aflatoon,
    Brilliant exactly as required, Thank you.

    D_Marcel, thank you for spending your time on this, as you can see I now have the answer.
    Regards, Peter.

  7. #7
    VBAX Contributor D_Marcel's Avatar
    Joined
    Feb 2012
    Location
    Tokyo
    Posts
    117
    Location
    Hum, I see. You need to consider always the range from second row of the current column until the previous row. Sorry for not being so helpful.

    Thanks Aflatoon.

Posting Permissions

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