VBA Help Needed - Class Module for CommandButton

Hoover889

New Member
Joined
Jul 29, 2013
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey Everyone,
I am trying to create Minesweeper in excel (to increase office productivity). I am already pretty good with VBA so creating it in a worksheet would be a cakewalk for me, so I am trying to create it in a user form.I also want to learn how to get better with class modules, which explains my approach. see below:

i have already created a user form to start the game ( select difficulty, or enter custom parameters for rows, cols and # of mines)
this user form takes the inputs and creates an array containing the mines and the number of mines adjacent to any given square.
the start game user form calls another userform containing the game itself. i used 2 for loops to create commandbuttons for each cell of the minesweeper field.

my issue is in adding code to each of the command buttons. everything I found on adding the code to each button using a class module is instructions to create a general purpose class module for handling all your events. i wanted to make a class module for just this button and it could also contain info like whether it has a mine, a flag, or has been clicked already.

Am i approaching this from the wrong direction. i was thinking maybe i should create a class module for the whole minefield tha contians multiple buttons, would that work?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This sounds really cool if you get it all working could you maybe upload the file so I could have a look at it.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top