Dynamic command button and timestamp

alfaspud

New Member
Joined
May 16, 2018
Messages
11
Hi

I am trying to set up a simple system to track equipment availability

I want to place a number of command buttons on a screen which will change colour (green to red and vice versa) and change caption (UP to DOWN and vice versa) every time the button is clicked
I also need to timestamp every click so that I can graph the equipment status

I have found VBA to do both of these separately on the site but I can't figure out how to combine into one

Many thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Perhaps something like this:-

Code:
Private [COLOR=navy]Sub[/COLOR] CommandButton1_Click()
[COLOR=navy]With[/COLOR] CommandButton1
    .Caption = IIf(.Caption = "UP", "Down", "UP")
    .BackColor = IIf(.BackColor = vbRed, vbGreen, vbRed)
[COLOR=navy]End[/COLOR] With
Range("A1").Value = Time()
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
I feel in the above code this line
Code:
Range("A1").Value = Time()
is to be changed as
Code:
Range("A" & Rows.Count).End(Xlup).Offset(1,0).Value = Time()
since you want chart.
 
Upvote 0
Perhaps something like this:-

Code:
Private [COLOR=navy]Sub[/COLOR] CommandButton1_Click()
[COLOR=navy]With[/COLOR] CommandButton1
    .Caption = IIf(.Caption = "UP", "Down", "UP")
    .BackColor = IIf(.BackColor = vbRed, vbGreen, vbRed)
[COLOR=navy]End[/COLOR] With
Range("A1").Value = Time()
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick


Thank you Mick

How do I get the timestamp to save in the next cell after every click (a1, a2, etc)?
 
Upvote 0
Hi guys
If I wanted to record the caption from the command button in the adjacent cell to the timestamp, how would I go about this?

Cheers
 
Upvote 0
Try:-
Code:
Private Sub CommandButton1_Click()
Dim Txt As String
With CommandButton1
    .Caption = IIf(.Caption = "UP", "Down", "UP")
    .BackColor = IIf(.BackColor = vbRed, vbGreen, vbRed)
    Txt = .Caption
End With
   With Range("A" & Rows.Count).End(xlUp)
       .Offset(1, 0).Value = Time()
       .Offset(1, 1).Value = Txt
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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