+ Reply to Thread
Results 1 to 9 of 9

Dynamic spin buttons to change cell link

  1. #1
    Registered User
    Join Date
    05-15-2018
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    5

    Dynamic spin buttons to change cell link

    I am very new to VBA and I am starting to learn it, but I was hoping someone here could help me figure this out.

    From what research I have done it seems the only way to change a cell link besides doing it manually is with VBA? So, what I would like to do is be able to change the cell link based on date. How I currently have my table set up is like this.

    Top row with a title and far right cell is '=today()' (lets call it J1)
    Row with header values - date (column A), value1, value2, value3, etc.
    row with spin buttons under the values I would like to increment.
    row with data

    Is there a way with VBA to set it up so the spinner checks $A4=$J$1 (date on row vs current date), and then updates the cell link to the cell on the row with the current date. That way I can increment/decrement the relevant row only (dynamically), while also preserving the data on older rows?

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Dynamic spin buttons to change cell link

    From the description it sounds like a named range based on offset might work. However, a sample workbook would probably clear things up a lot more.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    05-15-2018
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    5

    Re: Dynamic spin buttons to change cell link

    Ok, thanks. I made a simple mock up using the idea of keeping up with water intake.
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Dynamic spin buttons to change cell link

    I am not really happy with this implementation because it is extremely dependent on the setup of the sheet.

    For example, it breaks if the spinners are not named "Spinner 1" and "Spinner 2" or if the spinners are not in Columns C & D respectively or if the dates are not in Column B.

    I indicated in the code where the changes should be made in the code.

    In the thisworkbook module there is an open workbook event. This event runs the code when the workbook is opened, so you don't have to.
    Please Login or Register  to view this content.
    The main code is:
    Please Login or Register  to view this content.
    I wish that I could make this more flexible.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-15-2018
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    5

    Re: Dynamic spin buttons to change cell link

    When I downloaded the file you attached I got this error when I opened the sheets
    Capture1.PNG

    When I copy and pasted the code I changed all the names you commented to change. Maybe I missed something, because I got an 'Object required' error. Any thoughts on what I missed.

    Thanks again for providing the code, and with a prompt reply. Who knows how long this would of taken me by myself to figure out.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Dynamic spin buttons to change cell link

    Include the workbook so I can see where the error is happening.

  7. #7
    Registered User
    Join Date
    05-15-2018
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    5

    Re: Dynamic spin buttons to change cell link

    Here is the sheet
    Attached Files Attached Files

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Dynamic spin buttons to change cell link

    You did the right thing, but in the wrong place .

    The first bit of code should be in the ThisWorkbook "module"

    The main code should not be on the page for the spinners but in a regular module.

    The spinners themselves do not need to be associated with the macro.

    Here is what happens. When you open the workbook the macro in the ThisWorkbook module runs the main macro run automatically. The main macro looks for today's date (now in column C) and resets the spinners to point to the indicated column on that row.

    I moved your code parts to the proper places and reset the spinners to point to row 9 for test purposes. Then I closed the workbook and re-opened it and the spinners were reset to row 11 (for 5/18/2018) - so you nailed it. I did not have to change a thing.

    If you want to set the other spinners, that would take a minor adjustment to the code. Looking at how well you adapted this code, I have little doubt you could figure it out.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-15-2018
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    5

    Re: Dynamic spin buttons to change cell link

    Awesome, thank you so much for your help. Glad I joined this forum.

+ 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. Spin Buttons - Linked Cell to update when copied?
    By svpdebbie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2017, 09:18 AM
  2. Link cells to 100 spin buttons automatically
    By melbournelyn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2014, 06:17 AM
  3. Macros with buttons, spin buttons, scroll buttons, etc.
    By qqbbppdd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2013, 09:34 AM
  4. Link spin button to a different cell according to an if statement
    By depastle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2012, 02:51 PM
  5. Spin button link to another cell
    By jnick in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-26-2012, 11:38 AM
  6. [SOLVED] Change listbox link cell with command buttons
    By zplugger in forum Excel General
    Replies: 1
    Last Post: 08-12-2012, 06:43 PM
  7. Spin Button will not link to cell
    By elliotl in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-20-2009, 03:10 PM

Tags for this Thread

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