+ Reply to Thread
Results 1 to 5 of 5

Buttons to increment adjacent cell values

  1. #1
    Registered User
    Join Date
    12-13-2013
    Location
    Espoo, Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Buttons to increment adjacent cell values

    Hi everyone, my first post on here - I hope you can help me!

    I am trying to create some buttons which increment the value of a nearby cell up or down depending on whether the "+" or "-" button was clicked. Let me explain further....

    I have a long table of data containing names of cards, and I want the user to be able to record the number of each card that they own. I thought the easiest way would be to have a spin button next to each row of the table where the user can click the Up and Down buttons to increment the number in the "Owned" column +/-1.

    I can make this work fine for one row of the table, by using the following code attached to the SpinButton1 (which is located one cell to the right of the "Owned" column):

    Please Login or Register  to view this content.
    My problem is that I will have hundreds of these things and I think I'm right in saying that each new button will have to have a unique name, meaning I will have to copy/paste this code for each one and change the reference to the button (i.e. SpinButton2,3,4,5..... etc) which would be very time consuming. Is there an easy way to do this? Can anyone please suggest a way of assigning this code to a whole stack of spin buttons?

    Thanks in advance, guys

  2. #2
    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: Buttons to increment adjacent cell values

    Hi, jaskamakkara,

    you might use Class programming to do so. But I suggest to have a look at the events BeforeDoubleClick and BeforeRightClick behind the sheet which may reduce the programming as the codes go behind teh sheet (sample is for Column 3 = C starting at row 3):
    Please Login or Register  to view this content.
    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

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Buttons to increment adjacent cell values

    Maybe try moving the button?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-13-2013
    Location
    Espoo, Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Buttons to increment adjacent cell values

    Thank you both for your fine suggestions, I think I'll go with millz suggestion for moving the button. This works really nicely and doesn't require a huge number of buttons and coding.

    HaHoBe, I was wondering if your idea could be changed slightly so that instead of running the code on DoubleClicks and RightClicks, it ran when the user tried to type a + or - sign into a cell, i.e. it would increment the value up or down? Is it possible to capture such keystrokes and prevent them from having their normal effect (which, in this case, would be to type a + or - sign into the cell)?

    Thanks guys, I really appreciate your help.

  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: Buttons to increment adjacent cell values

    Hi, jaskamakkara,

    just the entering of either a + or a - sign will bring Excel to guess that you want to enter a formula - you would need to preceed that sign with an apostrophe to make it text. What you may consider to use Data/Validation and take the event of any change to trigger the macro.

    Ciao,
    Holger

+ 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. Macro to find all specific values in column and replace adjacent cell values
    By dblock02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2013, 06:03 AM
  2. [SOLVED] Increment a number based on the text in the adjacent column
    By lday75 in forum Excel General
    Replies: 7
    Last Post: 07-27-2012, 03:42 PM
  3. Increment Certain Cell Values by 1
    By 911 in forum Excel General
    Replies: 4
    Last Post: 11-28-2010, 05:37 AM
  4. Increment Cell Values in excel
    By limca969 in forum Excel General
    Replies: 1
    Last Post: 05-23-2008, 11:43 AM
  5. [SOLVED] Auto-increment cell values by one
    By [email protected] in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-30-2005, 12:10 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