none
I am having trouble making a reset button in visual basic editor ms excel for my maze game project RRS feed

  • Question

  • I am having trouble making a reset button in visual basic editor ms excel for my maze game projecT

    Option Explicit

    Public OldPosition As Range

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If OldPosition Is Nothing Then Set OldPosition = Target.Parent.Range("AF9") 'adjust AF9 to your start position

        If Target.Interior.Color = vbBlack Or Target.Row = 1 Or Target.Column = 1 Or Intersect(Target, OldPosition.Offset(-1, -1).Resize(3, 3)) Is Nothing Then
            Application.EnableEvents = False
            OldPosition.Select
            Application.EnableEvents = True
        Else
            OldPosition.Interior.Pattern = xlNone
            Set OldPosition = Target
            OldPosition.Interior.Color = vbRed
        End If

        If Not Intersect(Target, Target.Parent.Range("V50")) Is Nothing Then
            MsgBox "you finished"
        End If
    End Sub

    This is the code i do not know what to add to make the reset button go back to AF9 the starting cell in my maze game


    Monday, October 21, 2019 8:29 PM

All replies

  • Hi conwrath,

    I don't know what you want to do in code you provided.
    (Your code makes an active cell located at [AF9], whenever SelectionChange event occurs.)
    In order to add [Reset] button, [Developer] - (Control)[Insert]  an ActiveX Control button.   

    Code in that button (default name: CommandButton1)
    Private Sub CommandButton1_Click()
        Range("AF9").Select
    End Sub

    Regards,

    Ashidacchi -- http://hokusosha.com

    Tuesday, October 22, 2019 2:19 AM