+ Reply to Thread
Results 1 to 4 of 4

how can I get a vba to change a formula when changing cells

  1. #1
    Registered User
    Join Date
    02-09-2015
    Location
    scotland
    MS-Off Ver
    2010
    Posts
    14

    how can I get a vba to change a formula when changing cells

    Hi, I have no idea how to do a VBA, but got one online which nearly does the job. Basically i have 2000 columns for 4000 rows, so manual copy and paste will take days. I have a blank column between each which i need a basic formula inserted. EG in cell D4 i need (C5-C4)/C4. The macro i have does this but it does not update the formula for D6 where i will need (C6-C5)/C5 and so on so forth instead it copies (C5-C4)/C4 into all the blank cells i need the formulas in? Can anyone help me please?
    This is the macro i am running at the moment:

    Sub fcopy()
    Dim r, c As Integer
    For r = 4 To 55
    For c = 4 To 20 Step 2
    Cells(r, c).Formula = "=(c5-c4)/c4"
    Next
    Next
    End Sub



    Thanks for any replies!
    Last edited by dissertationhelp; 02-09-2015 at 06:17 PM.

  2. #2
    Registered User
    Join Date
    02-09-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    6

    Re: Help! Simple problem for beginners! Vba not changing formula

    Not the fastest way to do it but try replacing:

    Cells(r, c).Formula = "=(c5-c4)/c4"

    with:

    Cells(r, c).Formula = "=(" + Cells(r, c - 1).Address + "-" + Cells(r - 1, c - 1).Address + ")/" + Cells(r - 1, c - 1).Address

  3. #3
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Help! Simple problem for beginners! Vba not changing formula

    You need to use relative referencing - something like:

    Please Login or Register  to view this content.

    Easiest way to get to grips with this is record a macro and use the "use relative references button"
    Please consider adding a * if I helped.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Help! Simple problem for beginners! Vba not changing formula

    title updated:
    Last edited by protonLeah; 02-09-2015 at 07:01 PM.
    Ben Van Johnson

+ 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] Changing sheet in a simple formula when dragging it
    By k.m. in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2013, 02:01 PM
  2. Enter simple changing formula in many but not all cells
    By Burley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2008, 02:14 PM
  3. [SOLVED] simple formula problem
    By Bob Bedford in forum Excel General
    Replies: 4
    Last Post: 02-24-2006, 07:00 AM
  4. [SOLVED] Simple Formula Problem
    By bj in forum Excel General
    Replies: 5
    Last Post: 08-19-2005, 08:05 AM
  5. [SOLVED] a simple v-look up formula problem
    By Ivan in forum Excel General
    Replies: 2
    Last Post: 04-17-2005, 07:06 AM

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