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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If your times are stored in regular 7:00 format like this,

BC
1TimeCounter
27:00
38:00
49:00
510:00
611:00
712:00
813:001
914:00
1015:00
1116:00
1217:00
1318:00
1419:00
1520:00

<tbody>
</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,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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