[英]How to define range around activecell based on a criteria
基本上,我正在開發一個掃雷游戲,除了一件東西外,我什么都不做。 我正在努力挖掘空白(從activecell挖掘),直到在各個方向上找到任何數字值為止。
這是我目前擁有的一部分。 我嘗試將偏移值聲明為變量,但沒有用。
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
我如何使每個單元格變成白色並擴展直到找到任何值(1到9)。
那是一個遞歸問題,您需要創建一個遞歸函數,我會為您解答
希望您能對我在這里所做的事情有所了解,
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.