Results 1 to 9 of 9

Thread: VB code to Run formula untill blank cell

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member swinnersmusic's Avatar
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0
    Rajest:
    also experiment with recording a macro.
    here is one that has captured entering a formula and filling it across:
    Code:
    Sub enterformula()
    '
    ' enterformula Macro
    '
    
    '
        Range("D6").Select
        ActiveCell.FormulaR1C1 = "4"
        Range("E6").Select
        ActiveCell.FormulaR1C1 = "=100*RC[-1]"
        Range("E6").Select
        Selection.AutoFill Destination:=Range("E6:L6"), Type:=xlFillDefault
        Range("E6:L6").Select
        Range("F9").Select
    End Sub
    regards
    Alan

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Okay, now I think I see what you want. If I am right, then you can do it using this single line of code...

    Code:
    Range(Range("D27"), Range("D27").End(xlToRight)).Formula = Range("D27").Formula
    More generally, where the cell reference could change, this macro...

    Code:
    Sub ExtendFormulaToRight()
      Dim StartCell As Range
      Set StartCell = Range("D27")
      Range(StartCell, StartCell.End(xlToRight)).Formula = StartCell.Formula
    End Sub
    Where I assume you might change the starting cell for your extending the formula to the right... just change the Set code line as needed.
    Last edited by Rick Rothstein; 05-16-2012 at 07:10 PM. Reason: Corrected code to move toward the right to find the blank cell

Similar Threads

  1. Replies: 13
    Last Post: 06-10-2013, 09:05 AM
  2. Removing unused Cell styles - need an efficient code
    By siddharthsindhwani in forum Excel Help
    Replies: 8
    Last Post: 04-15-2013, 07:12 AM
  3. Autofill the data based on non blank cell in next row?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 3
    Last Post: 11-29-2012, 04:16 PM
  4. Replies: 2
    Last Post: 09-24-2012, 11:19 PM
  5. Replies: 1
    Last Post: 04-24-2012, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •