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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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