+ Reply to Thread
Results 1 to 3 of 3

Excel formula format in VBA syntax

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Excel formula format in VBA syntax

    I have excel formulas that i have tested and got to work in the spreadsheet, I have typed a code which does most of all the same thing but i have encountered a problem with syntax. The issue seems to be that I cant get vba to recognize my if statement conditions (text). The excel formula should mirror the vba formula for the line commented match.

    Excell:
    =IF(E2&F2=B2&C2,"Y","N")

    VBA:
    'Insert Match Formulas
    Dim lLR As Long
    ' Dim Y As Integer
    ' Dim N As Integer
    lLR = Range("C2").End(xlDown).Row 'DEFINES RANGE LENGTH

    'Enter Formulas
    Range("W2:W" & lLR).FormulaR1C1 = "=ROUNDUP(MONTH(R[0]C[-1])/3,0)" 'TERM DATE QUARTER R2C3
    Range("X2:X" & lLR).FormulaR1C1 = "=YEAR(R[0]C[-2])" 'TERM DATE YEAR

    Range("AA2:AA" & lLR).FormulaR1C1 = "=ROUNDUP(MONTH(R[0]C[-1])/3,0)" 'PAYROLL QUARTER
    Range("AB2:AB" & lLR).FormulaR1C1 = "=YEAR(R[0]C[-2])" 'PAYROL YEAR
    Range("AC2:AC" & lLR).FormulaR1C1 = "=IF(R[0]C[-6]&R[0]C[-5]=R[0]C[-2]&R[0]C[-1],Y,N)" 'MATCH

    Range("AF2:AF" & lLR).FormulaR1C1 = "=IF(R[2]C[29]=Y,0,R[2]C[31])" 'CONTRIBUTION QUARTER MATCH

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Excel formula format in VBA syntax

    You need to wrap the Y N in quotes. In VBA you need to double up the quotes when used within a set of quotes.

    Untested but should work,

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Re: Excel formula format in VBA syntax

    That worked perfectly, I had tried removing them, having only one set and other things. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel Formula To VBA Syntax
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2015, 05:43 AM
  2. make syntax of max if in vb excel 2007? (not formula)
    By andyshera in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 04:01 AM
  3. Printing Formula Syntax in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-15-2007, 02:46 AM
  4. Displaying Formula Syntax in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-15-2007, 02:44 AM
  5. [SOLVED] What is the syntax for the IF formula in Excel?
    By Christina in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-10-2005, 06:05 PM

Tags for this Thread

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