Consulting

Results 1 to 4 of 4

Thread: problem inserting formula with R1C1

  1. #1
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    2
    Location

    problem inserting formula with R1C1

    Dear All,
    I have a small problem trying to inserting automatically a formula with VBA in a cell. In practice I need to add an element to an enumerated list and in the formula there should be the variable that indicates the number of this element. To be more clear I post the code:


    [VBA]
    Sub addel()
    Dim nEL As Integer, inPos As Integer, eID As Integer
    Dim strFor As String

    nEL = 0

    Do While Range("eList").Offset(nEL, 0) <> ""
    nEL = nEL + 1
    Loop

    Range("eList").Offset(nEL, 0) = "Element " & nEL
    strFor = "= INDEX('Element" & nEL & "'!$C:$C,MATCH(""Name"",'Element " & nEL & "3'!$A:$A,FALSE))"
    Range("eList").Offset(nEL, 1).FormulaR1C1 = strFor

    End Sub


    [/VBA]

    Unfortunately I get always an application-defined or object-defined error. Some of you maybe with external eyes can see properly my mistakes and this would be great.
    Thank you in advance,
    Luca.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You should be using the Formula property, not the FormulaR1C1 property, t he formula string is using A1 notation.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    2
    Location
    I tried to use the formula property but it gives me the same mistake

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It works for me, although I notice that the formula refers to two different sheets.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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