Results 1 to 6 of 6

Code to fill down formula

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Code to fill down formula

    Hello.
    I ran the code below but it did not execute at all and instead highlighted in yellow a part of the code (see red font). This is the workbook i'm working with Fill Down Formula.xlsm

    Sub filldownformula()
    Dim ws As Worksheet:    Set ws = Sheets("Sheet1")
    Dim lr As Long
    Dim lc As Long
    Dim rcell As Range
    
    lr = ws.Range("A" & Rows.Count).End(xlUp).Row
    lc = ActiveSheet.UsedRange.Columns.Count
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    For Each rcell In ws.Range(Cells(18, lc - 1))
    rcell.FormulaR1C1 = "=RC[-2]*" & ws.Range("A1").Value
    Next rcell
    
    ws.Range(Cells(18, lc)).FormulaR1C1 = "=RC[-2]*RC[-1]"
    
    ws.Range(Cells(18, lc - 1)).Select
    ws.Range(Cells(18, lc)).Select
    Selection.Resize(lr - 18 + 1, 2).FillDown
    
    Cells(lr, lc).Formula = "=SUM(" & Cells(18, lc).Address & ":" & Cells(lr + 1, lc).Address & ")"
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
    End Sub
    Any ideas?
    Thanks.
    Last edited by kosherboy; 02-07-2014 at 12:11 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] help on vba code to fill range with formula to all splited files
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2014, 11:02 PM
  2. VBA code to fill blank cells with variable formula
    By Khen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2014, 08:24 AM
  3. Replies: 6
    Last Post: 11-28-2012, 07:29 PM
  4. Auto fill text using formula or code
    By nicmarty in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-29-2010, 09:26 AM
  5. Fill formula with code
    By WhiteKelso in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-15-2007, 05:28 PM

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