Help with a Class Module for 100 Command Buttons with exactly the same code just different rows.

jmp630

New Member
Joined
May 13, 2020
Messages
1
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
VBA Code:
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect Password:="password1"
Dim rw As Long
Dim sh As Worksheet
Set sh = Sheet1
rw = 3
If sh.Range("F" & rw).Value = "" Then
sh.Range("F" & rw).Value = Time()
Worksheets("Dashboard").Range("C" & rw, "Q" & rw).Interior.ColorIndex = 6
Range("C" & rw) = "Call Pending"
Else
If sh.Range("G" & rw).Value = "" Then
sh.Range("G" & rw).Value = Time()
Worksheets("Dashboard").Range("C" & rw, "Q" & rw).Interior.ColorIndex = 43
Range("C" & rw) = "Dispatched"
Else
If sh.Range("H" & rw).Value = "" Then
sh.Range("H" & rw).Value = Time()
Worksheets("Dashboard").Range("C" & rw, "Q" & rw).Interior.ColorIndex = 4
Range("C" & rw) = "Responding"
Else
If sh.Range("I" & rw).Value = "" Then
sh.Range("I" & rw).Value = Time()
Worksheets("Dashboard").Range("C" & rw, "Q" & rw).Interior.ColorIndex = 3
Range("C" & rw) = "On Scene"
Else
If sh.Range("J" & rw).Value = "" Then
sh.Range("J" & rw).Value = Time()
Worksheets("Dashboard").Range("C" & rw, "Q" & rw).Interior.ColorIndex = 0
Range("C" & rw) = Date
Else
Dim pwd As String
Dim x As CommandButton
Dim rg As Range
pwd = InputBox("Please input the password", "Input Password")
If pwd = "" Then Exit Sub
If pwd = "Reset" Then
ActiveSheet.Unprotect Password:="password1"
Range("C" & rw, "J" & rw).Select
Selection.ClearContents
Range("L" & rw, "Q" & rw).Select
Selection.ClearContents
Range("D" & rw).Activate
ActiveSheet.Protect Password:="password1"
Else
MsgBox "Incorrect password"
End If
Exit Sub
End If
End If
End If
End If
End If
ActiveSheet.Protect Password:="password1"
 End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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