+ Reply to Thread
Results 1 to 7 of 7

vba FormulaR1C1

Hybrid View

  1. #1
    Registered User
    Join Date
    01-17-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Question vba FormulaR1C1

    how can i write a FormulaR1C1 in vba?
    i want to set the formula in cell V2 to "=IF(SUM(B2:U2)>0,SUM(B2:U2),"")"

    how can i do that in my macro?

    question2: how do i filldown column V?
    Last edited by .paul.; 01-26-2009 at 12:27 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    That's not an R1C1 formula. If you want to enter the formula you have,
    range("v2").formula = "=IF(SUM(B2:U2)>0, SUM(B2:U2), """")"
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-17-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: vba FormulaR1C1

    Quote Originally Posted by shg View Post
    That's not an R1C1 formula. If you want to enter the formula you have,
    range("v2").formula = "=IF(SUM(B2:U2)>0, SUM(B2:U2), """")"
    yeah i know. i wanted to convert it to a R1C1 formula...

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1)
    range("V2").formula = "=IF(SUM(B2:U2)>0,SUM(B2:U2),"""")"
    2) If you can find the last relevant row, then put it into a variable. Assuming that column A will give you the last row then
    lastrow = cells(rows.count,"A").end(xlup).row
    range("V2").autofill destination:=range("V2:V" & lastrow)
    rylo

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    How do you determine where to fill down to? This could be one way

    Option Explicit
    Sub addFormula()
        Dim LastRow As Long
        With Sheet1    '<-change the sheet reference
            LastRow = .UsedRange.Rows.Count
            .Range(.Cells(2, 22), .Cells(LastRow, 22)).FormulaR1C1 = _
            "=IF(SUM(RC[-20]:RC[-1])>0,SUM(RC[-20]:RC[-1]),"""")"
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    01-17-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: vba FormulaR1C1

    how do i mark this thread SOLVED?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: vba FormulaR1C1

    yeah i know. i wanted to convert it to a R1C1 formula...
    See VBA Help for the ConvertFormula method.

    how do i mark this thread SOLVED?
    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes
    Last edited by shg; 01-26-2009 at 12:15 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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