Forum Discussion
Macro button
- Apr 04, 2021
Near the end of the macro, change the part
With wsData.Cells(r, TimeCol + x) .Value = 1 .Interior.Color = vbYellow End Withto
With wsData.Cells(r, TimeCol + x) .Value = .Value + 1 .Interior.Color = vbYellow End WithAnd near the beginning, the line
If Time > TimeSerial(18, 30, 0) And Time < TimeSerial(5, 30, 0) Thenshould be
If Time > TimeSerial(18, 30, 0) Or Time < TimeSerial(5, 30, 0) ThenSee the attached version with the modified version of Subodh_Tiwari_sktneer's code.
Please find the attached with the code on Module1. I replaced the ActiveX Commandbuttons you inserted on Input Sheet with the Rectangular Shapes and renamed them properly to make it work correctly. Please don't mess with the names and captions of these buttons. The code on Module1 is assigned to all of these buttons.
Code on Module1:
Sub FillData()
Dim wsInput As Worksheet
Dim wsData As Worksheet
Dim shp As Shape
Dim TimeCol As Variant
Dim x As Long
Dim r As Variant
Dim EType As String
Dim Region As String
If Time > TimeSerial(18, 30, 0) And Time < TimeSerial(5, 30, 0) Then
MsgBox "Out of scheduled time!", vbExclamation
Exit Sub
End If
Set wsInput = ThisWorkbook.Worksheets("Input Sheet")
Set wsData = ThisWorkbook.Worksheets("Data Sheet")
Set shp = wsInput.Shapes(Application.Caller)
EType = shp.OLEFormat.Object.Caption
Region = Split(shp.Name, "_")(1)
If EType = "Emp" Then
x = 0
ElseIf EType = "Vet" Then
x = 1
End If
On Error Resume Next
TimeCol = Application.Match(CDbl(Time), wsData.Rows(3))
r = Application.Match(Region, wsData.Columns(1), 0)
On Error GoTo 0
If IsError(TimeCol) Then
MsgBox "No time slot was found on Data Sheet!", vbExclamation
Exit Sub
End If
If IsError(r) Then
MsgBox "No header for """ & Region & """ was found in column A of " & wsData.Name & "!", vbExclamation
Exit Sub
End If
With wsData.Cells(r, TimeCol + x)
.Value = 1
.Interior.Color = vbYellow
End With
Application.Goto wsData.Cells(r, TimeCol + x)
End Sub
- Phil CoxApr 04, 2021Copper Contributor
- Subodh_Tiwari_sktneerApr 04, 2021Silver ContributorYou're welcome Phil Cox! Got stuck in a project so couldn't reply in time but I am glad HansVogelaar tweaked it for you. 🙂
- Phil CoxApr 04, 2021Copper Contributor
One more thing. The count on the data sheet only goes to one. I would like to increase what ever number is there by 1 each time I click the bottom. So if I click it four times in one 15 min period it will show 4.
What I am trying to achieve is to track how many employees and veterans I pick up in my shuttle bus at each of my shuttle stops.
Thanks for your help.
Phil
- HansVogelaarApr 04, 2021MVP
Near the end of the macro, change the part
With wsData.Cells(r, TimeCol + x) .Value = 1 .Interior.Color = vbYellow End Withto
With wsData.Cells(r, TimeCol + x) .Value = .Value + 1 .Interior.Color = vbYellow End WithAnd near the beginning, the line
If Time > TimeSerial(18, 30, 0) And Time < TimeSerial(5, 30, 0) Thenshould be
If Time > TimeSerial(18, 30, 0) Or Time < TimeSerial(5, 30, 0) ThenSee the attached version with the modified version of Subodh_Tiwari_sktneer's code.