+ Reply to Thread
Results 1 to 5 of 5

issue with outcome of if/then statement in VBA

  1. #1
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 365
    Posts
    108

    issue with outcome of if/then statement in VBA

    Hi,

    I’ve got a problem with one of my if/then statements and I can’t seem to get it working. Most likely it’s an easy fix that I keep overlooking.
    I've set all criteria but as outcome i do not want a fixed type of text to be populated, but a formula need to be pulled in instead.

    Currently, when I run the formula, it only pull the text FALSE into the cells I have specified.
    Basically, if it meets my criteria it need to pull a NETWORKDAYS formula in to column AC.

    Please see attached file for details & macro.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-25-2013
    Location
    near Philly, PA USA
    MS-Off Ver
    Excel 2019
    Posts
    178

    Re: issue with outcome of if/then statement in VBA

    If you manually enter the =NETWORKDAYS(RC[-9],RC[-6],holidays)-1 does it work correctly?

  3. #3
    Registered User
    Join Date
    10-26-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: issue with outcome of if/then statement in VBA

    try this

    Cells(i, "AC").FormulaR1C1 = "=NETWORKDAYS(RC[-9],RC[-6],holidays)"

    instead of

    Cells(i, "AC").Value = ActiveCell.FormulaR1C1 = "=NETWORKDAYS(RC[-9],RC[-6],holidays)"

  4. #4
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: issue with outcome of if/then statement in VBA

    Where you have
    Please Login or Register  to view this content.
    I think you want
    Please Login or Register  to view this content.
    At the moment the effect of line 1 is 'cells(i,AC) is equal to the outcome of the true/false statement: activecellformula = the formula outlined'
    Which will very depending on which cell is active when the macro is run.

    Seems to me a simple mistake to do with turning a recorded macro into a streamlined macro.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  5. #5
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 365
    Posts
    108

    Re: issue with outcome of if/then statement in VBA

    I knew there was an easy solution to it.... :-)
    this works!!! Thread will be marked as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1