Consulting

Results 1 to 11 of 11

Thread: Solved: How do I code this

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location

    Solved: How do I code this

    In this spreadsheet I have a formula in D2 as

    " If(G2<0.01,"",If(G2>F2,"Y","N"))"

    If I code it as the below when added to the Sheet 1 code it asks me to create a Macro. But in the macro code it says "Compile Error "Expected end of Statement" at the "0.01" value.

    .Range.FormulaR1C1 = "=If(R[2]C[8]<"0.01","",If(R[2]C[8]>R[2]C[7],"Y","N")) it displays a Compile error when you try to run the code from the Macro ContractStatus.

    The object here is have the value in cell D2 ( actually all of the Range D2156) reflect if the value in G2 is "0" then show nothing, else if the value in G2 is greater than F2 then show the value "Y" else "N".

    By typing a date in column T and a value "Cleared" in Column U, the code (Kindly initially supplied by XLGibbs) copies and paste to the Sheet "Bucket History" and then resets the values in the Sheet 1 (Except it doesn't rest the Column D values)

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Hmmm... lost the attachment I see.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location

    Found it...

    Okay really found it this time...

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Try this.
    [vba]
    Range("D2156")= "=If(G2<0.01,"""",If(G2>F2,""Y"",""N""))"
    [/vba]

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Sorry, still didn't reset the formula for the cell in the row just copied.

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Sorry but I have no idea what you mean.

    You didn't post any code that copied a row.

    Unless it's in the attachment, which I'm about to download.

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Yep. Its in the attachment

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    So how did you try the code I posted and how did it not work?

  9. #9
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location
    If that does not work, you may try:

    [VBA]
    Range("D2156").Formula = "=If(G2<0.01,"""",If(G2>F2,""Y"",""N""))"
    [/VBA]

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    The problem may lie inside the macro I believe.

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Range("D2156").FormulaR1C1 = "=IF(RC[3]<0.01,"""",IF(RC[3]>RC[2],""Y"",""N""))"
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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