+ Reply to Thread
Results 1 to 3 of 3

Excel VBA Button Help

  1. #1
    Registered User
    Join Date
    11-29-2016
    Location
    Connecticut
    MS-Off Ver
    2016
    Posts
    2

    Excel VBA Button Help

    Hello. I just recently began to learn about writing code within excel VBA. I have a project for school where I must create a board game and I choose to use excel. I wanted to make a VBA version of connect 4 but was only able to make a mixture of connect 4 and tic tac toe. I am trying to add buttons above the 7 columns of boxes that will drop a chip into an empty column below. Right now, I can click any box and place a chip which is not true to connect 4 seeing that the chips must stack on top of each other. Can any one please help me with the code for this? I've attached a copy.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Excel VBA Button Help

    Try this
    (vba checks from bottom to top to see if button contains text and runs the code for the first button it finds which contains no text)
    The code for each of the top row buttons need modifying in the same way

    Please Login or Register  to view this content.
    Last edited by kev_; 11-30-2016 at 02:26 AM.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel VBA Button Help

    Hello rdroy1954,

    This is a late answer to your post but I hope you will find it useful. The attached workbook has your User form with a modification. Each vertical column has two player buttons "X" an "O". There are 12 total. When the user clicks a button that player's mark is added to the next cell in that column. After each player makes a choice, the macro checks for a win.

    I basically rewrote the code. While your code was working, it lacked the flexibility to accommodate the new changes. You will see this code uses a variety of techniques to simply the and streamline the code. If you were to turn this in as your own project, it would be obvious you had help. My goal is help you see and learn new ways of solving problems with VBA. The code is heavily documented but I am sure you will still have some questions. Please don't hesitate to ask me anything you have a question about.

    Here is the User Form code. The attached workbook contains the new changes and this code.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Leith Ross; 12-04-2016 at 09:36 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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. Excel 2013 won't run a macro attached to button created in excel 2003
    By Jonno1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-30-2020, 01:16 AM
  2. [SOLVED] Form - select button & retrieve button name or button's caption
    By lexusap in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-27-2016, 12:28 AM
  3. vba code to disable only close button and close through a button in Excel workbook
    By atif_ar in forum Excel Programming / VBA / Macros
    Replies: 47
    Last Post: 11-23-2014, 02:41 PM
  4. VBA Code to Disable Excel Close button also disabling my Close Button
    By akynyemi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-28-2013, 12:56 PM
  5. Macro button to save file in excel, format of excel
    By sunshne900 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2013, 02:40 PM
  6. BUTTON TO CLOSE AND OPEN EXCEL FILE( excel vba)
    By TRADER_M in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 08:48 PM
  7. Disable 'Exit Excel' button in Excel 2007
    By Testing213 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2008, 01:30 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