기본적으로 MS Excel로 지뢰밭 게임을 만드는 중입니다. 그리고 지금은 오류가 나는 나의 '새로운 게임'을 실행하려고 '하고 프로그래머에게 각 myCell에서 범위 (strBoardSize)각 셀을 반복합니다.
내 전체 코드에 대한
에 뭔가 말을 한 후 나오고있다 범위 내의 모든 셀을 보도록 만들어지고 셀이 원하는 수만큼 옆에 있으면 주변에있는 항목의 수를 표시합니다. 코드를 작성하는 더 쉬운 방법이있을 수 있음을 이해하지만, 초보자 인 이유를 판단하지 마십시오.
는 strBoardSize를 선언 당신이 변수 "strBoardSize"를 작성하고 당신이되고 싶은 범위를 설정해야 할 것 같습니다Sub WorkOutMines() Dim myCell As Range Dim intCountSurroundingCells For Each myCell In Range(strBoardSize) intCountSurroundingCells = 0 If myCell.Value = "x" Then Else If myCell.Offset(-1, -1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(-1, 0).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(-1, 1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(0, -1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(0, 1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(1, -1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(1, 0).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If myCell.Offset(1, 1).Value = "x" Then intCountSurroundingCells = intCountSurroundingCells + 1 End If If intCountSurroundingCells = 0 Then Else myCell.Value = intCountSurroundingCells End If End If Next End Sub
Sub SetBoardSize() strBoardSize = "Board9x9" End Sub
'strBoardSize'의 값은 무엇입니까? –
수정되었는데 잘못 되었나요? –
"Board9x9"등과 같은 명명 된 범위가 있습니까? 그렇지 않다면 그것들을 생성하거나 범위를'WorkOutMines' 서브에 어떻게 전달할 것인지를 바꿀 필요가 있습니다. –