My Macro is too long!?!

dukeofscouts

Board Regular
Joined
Jan 19, 2009
Messages
146
Well the good news is that I got the macro written correctly. Bad news is that it is too long. So here goes my question: How can I get this shorter?

Background is that I'm working on an excel workbook to solve Soduko puzzels. I wanted to push my excel skills and see how I could use excel to mimic some tools other programs use to help beginners solve puzzels. So far things are going well.
-I have the Several 27*27 puzzel ranges set up,
--First starts in B2 and is a merged and copied down to a 9*9 grid. This is used to maintain the original puzzel so I can go back and start over,
--the second starts in AD2, this also is a 9*9 merge and copy that simply copies the the range from B2, I then can overwrite the formulas with my values here.
--The third in BF2 is a 27*27, this range creates the "pencil marks" showing what a each cell could be in the range AD2 based on the values in AD2.
--Finally (well not really but the others wont have any effect on this) there is CH2 a 27*27 that checks to see based off of the values in BF2 to see if there are any cells in AD2 that are not filled yet, but that there is a set value for it to be.

I've changed all TRUE and FALSE statements to 1 or 0 so that I could use custome formatting to edit what each cell displayes or hides without using the IF function.

My macro works to see if there is cell that the computer knows the answer to that I have not entered yet, copies the answer from the pencil marks, and puts it in the correct slot in the puzzle range.

I'm still a rookie at this so I typed it all out, not knowing how to create loops in macros yet.

Any suggetions as to what I can cut out, or how to change this to loop?
 
That's really cool. Not going to lie, I don't understand over half the code, but very cool. That said, if I follow correctly what I do understand this is way better than what I've got now. That will be my next challange then. Thanks for Sharing.


Hi,

FYI, the basic strategy that the code follows is:
Initialise the Grid array with either the entered number or the 'candidate' numbers 123456789.

Then for each row, column and 3 x 3 box, extract the set of cells into a working array and call a function which will scan thru the set and if there s a single number in a cell, remove that number from all other cells in the set and indicate that a change has occurred.

If a change HAS occurred, it is written back to the Grid array and does it all over again. If no changes occurred for the iteration, it has finished processing, and writes the results to the w/sheet.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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