+ Reply to Thread
Results 1 to 7 of 7

Add a value to current cell using FormulaR1C1

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Add a value to current cell using FormulaR1C1

    I need to add value in cell Z7 to the value in J2 (and retain the value in J2).

    This does not work (adding another cell to same cell)

                            Cells(2, 10).FormulaR1C1 = "=RC+R[5]C[16]"
    But, this works. (Adding two different cells - Y7 and Z7 - and storing the sum in J2)

                            Cells(2, 10).FormulaR1C1 = "=R[5]C[15]+R[5]C[16]"
    What do I need to do to make the first command work?

    tia
    ajay
    Last edited by ajaykgarg; 11-24-2013 at 07:19 AM.

  2. #2
    Forum Contributor wakeupcall's Avatar
    Join Date
    02-29-2012
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    155

    Re: Add a value to current cell using FormulaR1C1

    Hi Ajay

    perhaps something using similar logic

    Sub Replace()
    
    Dim newv As Long
    Dim oldv As Long
    oldv = ActiveSheet.Range("J2").Value
    
    newv = oldv + Range("Z7")
    Range("J2").Value = newv
    
    End Sub
    Liked the answer given? click * to say so

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add a value to current cell using FormulaR1C1

    Hi, ajaykgarg,

    what you try to do looks like creating a circular reference to a cell where you want to insert a formula - you could place the current value of the cell and add the address of new one to the formula instead if you really want a formula in the cell.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: Add a value to current cell using FormulaR1C1

    Quote Originally Posted by HaHoBe View Post
    Hi, ajaykgarg,

    what you try to do looks like creating a circular reference to a cell where you want to insert a formula - you could place the current value of the cell and add the address of new one to the formula instead if you really want a formula in the cell.

    Ciao,
    Holger
    Hi Holger

    You are right. I made it work without a formula, but I need the formula, so users can change values in future, and see the updated results.

    I need to do this for thousands of values.
    I can maybe use a hidden sheet to do it for every value.

    I will go for that option, if I cant find any other simpler way of doing it.

    Thanks
    Ajay
    Last edited by ajaykgarg; 11-24-2013 at 07:40 AM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add a value to current cell using FormulaR1C1

    Hi, Ajay,

    With Cells(2, 10)
      .FormulaR1C1 = "=" & .Value & "+R[5]C[16]"
    End With
    Ciao,
    Holger

  6. #6
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: Add a value to current cell using FormulaR1C1

    Hello

    I believe this way, I will get the value in J2, but not the formula.

    I need to retain the formula (J2 + Z7) in J2, as I want to let users change Z7, and show new sum in J2.

    Thanks
    Ajay

  7. #7
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: Add a value to current cell using FormulaR1C1

    Thanks, Holger. That works perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] copy and paste in current active cell, and need current date then scroll down 140 lines
    By vengatvj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2013, 03:40 AM
  2. [SOLVED] Clear Cell in VBA not FormulaR1C1 = ""
    By jake.masters in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2012, 01:43 PM
  3. Using FormulaR1C1 to input complex formula into cell
    By kevnin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2008, 07:51 PM
  4. [SOLVED] Formular1c1
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2005, 05:05 PM
  5. FormulaR1C1
    By Aksel Børve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2005, 06:06 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