adding to a cell in a different row based on what time it is when a button is clicked

exhatcher

New Member
Joined
Jun 7, 2016
Messages
3
I am trying to make a sub that when run (a button is clicked) it adds one to the value of a particular row based on what time it is.
for example, my sheet has an hour in 8 rows column B (based on what shift is using the program the times will differ) When the button is hit It needs to add 1 to the cell to the right of whatever hour it is, so if it is 7:35 when the button is hit it needs to add 1 to whatever number is in the row for 7:00.

I have no Idea how to write code for this, any help would be appreciated!

Maybe have it call out the hour from the current time and match it to the cell with that hour in it, store that row then use that row and the set column of the input cells to identify the range that needs to have 1 added to it.

can anyone help me with this code? thank you!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If your times are stored in regular 7:00 format like this,

BC
TimeCounter

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]7:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]8:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]9:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]10:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]11:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]12:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]13:00[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]9[/TD]
[TD="align: right"]14:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"]15:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"]16:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: right"]17:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]
[TD="align: right"]18:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]
[TD="align: right"]19:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]15[/TD]
[TD="align: right"]20:00[/TD]
[TD="align: right"][/TD]

</tbody>
Sheet4



then this macro will add 1 to the corresponding column:
Rich (BB code):
Sub AddOne()

    h = Hour(Now)
    For Each c In Range("B2:B15")
        If h = Hour(c) Then
            c.Offset(0, 1) = c.Offset(0, 1) + 1
            Exit For
        End If
    Next c
    
End Sub

The range in red is where your times are, and the 1 in red means to add to the column 1 to the right of B.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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