convert formula to VBA code

  • Hi guys,

    I'm currently have this formula to populate the cells according to date. I would like to convert the formula to VBA.

    =IF(AND(C$1>=INT($O7),C$1<=INT($P7)),"1.1","")& IF(AND(C$1>=INT($Q7),C$1<=INT($R7)),"1.2","")&IF(AND(C$1>=INT($S7),C$1<=INT($T7)),"1.3","")

    I try to write some codes, but don't know how to allow the codes to read until the end. I also need to insert value ("1.1") under each date that meets the requirement.

    I need the VBA to continue read through the whole row and compare with Start/End dates. If the dates in row are within Start/End dates, then insert value "1.1".
    I have attached the file to show what i want to do.

    Thank you.

  • Re: convert formula to VBA code

    Try this.

    Sub Formula()
    Range("C2:L4").Formula = _
    "=IF(AND(C$1>=INT($O7),C$1<=INT($P7)),""1.1"","""")& IF(AND(C$1>=INT($Q7),C$1<=INT($R7)),""1.2"","""")&IF(AND(C$1>=INT($S7),C$1<=INT($T7)),""1.3"","""")"
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!