+ Reply to Thread
Results 1 to 3 of 3

Copy a formula to specific number of cells to the right

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2007
    Posts
    60

    Copy a formula to specific number of cells to the right

    Hello,

    I am trying to copy a formula to say 12 cells to the right of active cell - I tried to use the following code, but it's copying the formula to entire cells to the right.

    Question is how to modify the code to copy the formula to only specific number (that I know) of cells to the right.

    
    ActiveCell.FormulaR1C1 = "=R[-4]C"
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.FillRight
    Appreciate your help in advance.

    Thanks, DoubleA

  2. #2
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    This should work. Just change the "12" to whatever number you want to copy over to.
      Dim myNumber As Integer
      myNumber = 12 'This is the number of cells to copy to the right
      ActiveCell.FormulaR1C1 = "=R[-4]C"
      Range(ActiveCell.Address, ActiveCell.Offset(0, myNumber)).Select
      Selection.FillRight
    If you wanted could do something like this:
    myNumber = InputBox("How many cells to the right?")
    or link myNumber to a cell value somewhere in your spreadsheet
    myNumber = range("A2").value
    Last edited by Ikaabod; 08-21-2007 at 06:33 PM.

  3. #3
    Registered User
    Join Date
    08-20-2007
    Posts
    60
    Thanks a lot, this is exactly what I wanted..

+ Reply to Thread

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