Reputation: 1
Basically I am building a minesweeper game and I got everything right apart from 1 thing. I am struggle to excavate blanks (from activecell) until any number value is found in every direction.
This is part of what I currently have. I tried declare offset values as variables but did not work.
If ActiveCell.Value = "" Then
ActiveCell.Interior.TintAndShade = 0
ActiveCell.Offset(1, 0).Interior.TintAndShade = 0
ActiveCell.Offset(1, -1).Interior.TintAndShade = 0
ActiveCell.Offset(0, -1).Interior.TintAndShade = 0
ActiveCell.Offset(-1, -1).Interior.TintAndShade = 0
ActiveCell.Offset(-1, 0).Interior.TintAndShade = 0
ActiveCell.Offset(-1, 1).Interior.TintAndShade = 0
ActiveCell.Offset(0, 1).Interior.TintAndShade = 0
ActiveCell.Offset(1, 1).Interior.TintAndShade = 0
End If
How do I get every cell turn to white and expand until any value (1 to 9) is found.
Upvotes: 0
Views: 27
Reputation: 605
Thats a recursive problem , you need to craete a recursive function i will answer for you
I hope you can get some "Logic" about what i tried to do here ,
Public Sub checkUntilItsHaveNumber(ByVal c As Range)
If c.Value = "" Then
c.Interior.TintAndShade = 0
Call checkUntilItsHaveNumber(c.Offset(1, 0))
Call checkUntilItsHaveNumber(c.Offset(-1,0))
Call checkUntilItsHaveNumber(c.Offset(0, 1))
Call checkUntilItsHaveNumber(c.Offset(0, -1))
End If
End Sub
Upvotes: 1