Results 1 to 12 of 12

Macro to autofill a IF function based on the column before it

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2007
    MS-Off Ver
    Excel 2007
    Posts
    94

    Macro to autofill a IF function based on the column before it

    I am working on a macro that designed to reformat data and it is coming along pretty well, but I keep getting the following error

    Run-time error '1004':
    Application-defined or object-defined error

    Here is the code

    Sub BeginReformat()
    'Piecing together a macro
        ActiveWorkbook.Sheets(1).Sort.SortFields.Clear
        ActiveWorkbook.Sheets(1).Sort.SortFields.Add Key:=Range("R:R" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Sheets(1).Sort
            .SetRange Range("A:V")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
            Range("C:C,E:E,F:F").Select
            Range("F1").Activate
            Selection.Insert Shift:=xlToRight
            Range("C2").Select
            Range("C2").FormulaR1C1 = "=(RC[20]&""-""&RC[-2]&""-""&RC[1])"
            LastRow = ActiveSheet.UsedRange.Rows.Count
            Range("C2").AutoFill Destination:=Range("C2:C" & LastRow)
            Range("F2").Select
            Range("F2").FormulaR1C1 = "=IF(Sheet1!$A$1 RC[-1]>=1,""Yes"",""No"")"
            LastRow = ActiveSheet.UsedRange.Rows.Count
            Range("F2").AutoFill Destination:=Range("F2:F" & LastRow)
        End With
    End Sub
    The offending line is
    Range("F2").FormulaR1C1 = "=IF(Sheet1!$A$1 RC[-1]>=1,""Yes"",""No"")"

    I am sure that I calling this wrong but I am unsure as to how I should be calling it
    Last edited by capnhud; 06-16-2010 at 11:58 AM.

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