How to Reset Count Value in textbox in user form

Sufiyan97

Well-known Member
Joined
Apr 12, 2019
Messages
1,538
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
I am using below code to play a number shuffle game

How can I reset the count in textbox1?

VBA Code:
Option Explicit

Sub EmptySpotChecker(ByRef Butt1 As CommandButton, ByRef Butt2 As CommandButton)

If Butt2.Caption = "" Then

Butt2.Caption = Butt1.Caption

Butt1.Caption = ""

End If



End Sub



Sub SolutionChecker()



If UserForm.CommandButton1.Caption = "1" And UserForm.CommandButton2.Caption = "2" And UserForm.CommandButton3.Caption = "3" And _

UserForm.CommandButton4.Caption = "4" And UserForm.CommandButton5.Caption = "5" And UserForm.CommandButton6.Caption = "6" And _

UserForm.CommandButton7.Caption = "7" And UserForm.CommandButton8.Caption = "8" And UserForm.CommandButton9.Caption = "9" And _

UserForm.CommandButton10.Caption = "10" And UserForm.CommandButton11.Caption = "11" And UserForm.CommandButton12.Caption = "12" And _

UserForm.CommandButton13.Caption = "13" And UserForm.CommandButton14.Caption = "14" And UserForm.CommandButton15.Caption = "15" Then





Dim a As Integer

a = MsgBox("Well done, you are a Dazzling Star", vbOKOnly, "Xyz Creations")







End If



UserForm.Count = UserForm.Count + 1

UserForm.Caption = "Number of Clicks " & UserForm.Count

UserForm.TextBox1.Text = UserForm.Caption

End Sub



Sub Shuffle()



Dim a(15), i, j, RN As Integer

Dim flag As Boolean

flag = False

i = 1

a(j) = 1



Do While i <= 15

Randomize

RN = CInt(Int((15 * Rnd()) + 1))

For j = 1 To i

If (a(j) = RN) Then

flag = True

Exit For

End If

Next

If flag = True Then

flag = False

Else

a(i) = RN

i = i + 1

End If

Loop







UserForm.CommandButton1.Caption = a(1)

UserForm.CommandButton2.Caption = a(2)

UserForm.CommandButton3.Caption = a(3)

UserForm.CommandButton4.Caption = a(4)

UserForm.CommandButton5.Caption = a(5)

UserForm.CommandButton6.Caption = a(6)

UserForm.CommandButton7.Caption = a(7)

UserForm.CommandButton8.Caption = a(8)

UserForm.CommandButton9.Caption = a(9)

UserForm.CommandButton10.Caption = a(10)

UserForm.CommandButton11.Caption = a(11)

UserForm.CommandButton12.Caption = a(12)

UserForm.CommandButton13.Caption = a(13)

UserForm.CommandButton14.Caption = a(14)

UserForm.CommandButton15.Caption = a(15)

UserForm.CommandButton16.Caption = ""



End Sub



Below is a code which counts the clicks:
I want a code to number of counts to be zero

VBA Code:
UserForm.Count = UserForm.Count + 1

UserForm.Caption = "Number of Clicks " & UserForm.Count

UserForm.TextBox1.Text = UserForm.Caption
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You don't say under what conditions you want to reset to zero but here is the code to do it. How and where is Count declared?

VBA Code:
UserForm.Count = 0
UserForm.Caption = "Number of Clicks " & UserForm.Count
UserForm.TextBox1.Text = UserForm.Caption
 
Upvote 0
Solution
You don't say under what conditions you want to reset to zero but here is the code to do it. How and where is Count declared?

VBA Code:
UserForm.Count = 0
UserForm.Caption = "Number of Clicks " & UserForm.Count
UserForm.TextBox1.Text = UserForm.Caption

I will create a new command button for reset.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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