+ Reply to Thread
Results 1 to 4 of 4

Changing the cell that a formula references using command button

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Changing the cell that a formula references using command button

    I have a data entry form on excel and I want to put in the top corner the date and time that the last entry was made by simply making the cell refer to the date and time from the previous record.

    A simple formula of ='Sheet 1'!A3 will return the first value, but I want A3 to become A4 then A5 and so on each time the command button is pressed.

    I can get VBA to make the contents of the cell equal to the formula required to retrieve the data from the other sheet, so:
    Worksheets("Sheet 2").Range("J1") = "='Sheet 1'!A3" but I couldn't work out how to get that line of VB code to increase the '3' by 1 each time.

    So I tried turning A3 in to the cordinates of 1,I and then having I increase by one each time, but VBA returns an error and I'm unsure why:
    Worksheets("Sheet 2").Range("J1") = "='Sheet 1'!1,3"

    Simply, I would like the cell reference in J1 which is referencing A3 in the other sheet to increase by 1 each time the code runs.

    Unfortunately I can't attach the file as it would take forever to scrub it of sensitive data. Thanks.

  2. #2
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Changing the cell that a formula references using command button

    In J2 try = Max(Sheet1!A3:A100000)

    Chris

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Changing the cell that a formula references using command button

    Often the simplest of solutions.
    Works perfectly, thank you.

  4. #4
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Changing the cell that a formula references using command button

    Keeping things simple means that when I revisit something years later I can still work out what I've done.

    Simple solutions from a simple man. Just have to have a twisted view on the world.

    Chris

+ 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. Command button do not activate until changing cell.
    By Hybris6 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-23-2013, 09:04 AM
  2. [SOLVED] How to copy formula's from a Relative cell without changing the cell references
    By mowens74 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-03-2013, 04:42 AM
  3. [SOLVED] Changing ODBC command texts and refreshing via command button
    By milty456 in forum Excel General
    Replies: 2
    Last Post: 10-09-2012, 12:06 PM
  4. Formula automatically changing cell references
    By Nina in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2006, 06:00 PM
  5. Command Button with relative references ???
    By marcusjb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2005, 01:11 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