+ Reply to Thread
Results 1 to 2 of 2

Error inserting formulas into a range object

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2005
    Posts
    3

    Error inserting formulas into a range object

    Greetings all,

    I am receiving an 'Application-defined or Object-defined' Run-time error on some simple code but I can not for the life of me get it to work. I am using 2003 and trying to just insert a formula into a selected range of rows down a column.

    Dim cell As Range
    
    Sub insertLineSellFormula()
        For Each cell In Selection
            cell.Formula = "=OFFSET(" & cell.Address & ",0,-2)/(1-OFFSET(" & cell.Address & ",0,-1)"
        Next cell
    End Sub
    Oddly enough I can reference the cell object to alter other properties of it within the loop (clear it, apply conditional formats, ect.) but when I attempt to insert the formula or a .Value I get the run-time error.

    As always any insight you guys may have is very much appreciated.

    Thanks!

  2. #2
    justahelper
    Guest

    RE: Error inserting formulas into a range object


    I think the end of your formula is missing a bracket.
    ",0,-1)"
    should be
    ",0,-1))"


    "Josh22" wrote:

    >
    > Greetings all,
    >
    > I am receiving an 'Application-defined or Object-defined' Run-time
    > error on some simple code but I can not for the life of me get it to
    > work. I am using 2003 and trying to just insert a formula into a
    > selected range of rows down a column.
    >
    >
    > Code:
    > --------------------
    >
    > Dim cell As Range
    >
    > Sub insertLineSellFormula()
    > For Each cell In Selection
    > cell.Formula = "=OFFSET(" & cell.Address & ",0,-2)/(1-OFFSET(" & cell.Address & ",0,-1)"
    > Next cell
    > End Sub
    > --------------------
    >
    > Oddly enough I can reference the cell object to alter other properties
    > of it within the loop (clear it, apply conditional formats, ect.) but
    > when I attempt to insert the formula or a .Value I get the run-time
    > error.
    >
    > As always any insight you guys may have is very much appreciated.
    >
    > Thanks!
    >
    >
    > --
    > Josh22
    > ------------------------------------------------------------------------
    > Josh22's Profile: http://www.excelforum.com/member.php...o&userid=24080
    > View this thread: http://www.excelforum.com/showthread...hreadid=393114
    >
    >


+ 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