Forum Discussion
Can anyone help with a command button problem please?
Hello. I am a complete novice on Excel but using google and you tube I can put basic macros etc in to play. I have created a button on a spreadsheet that when clicked creates a timestamp in a cell. I now need that button to check another cells content prior to creating a timestamp.
At present the button contains this code:-
Private Sub CommandButton1_Click()
Range("F3").Value = Now()
End Sub
I am now needing it to perform the following tasks:-
1st - Check cell H3 to see if it contains the word "Available"
2nd - If Cell H3 = "Available", then open a pop up box with the message "Please allocate a task to the driver before deployment"
3rd - If cell H3 does not = "Available" then create a timestamp in cell F3
I have tried google and you tube, but everything I try seems to come up with errors. I would be grateful for any help anyone can offer me. Thank you
try:
Private Sub CommandButton1_Click()
Range("F3").Value = Now()
If Range("H3") = "Available" Then
MsgBox "Please allocate a task to the driver before deployment"
Else
Range("F3").Value = Now()
End If
End Sub
3 Replies
- Lorenzo KimBronze Contributor
try:
Private Sub CommandButton1_Click()
Range("F3").Value = Now()
If Range("H3") = "Available" Then
MsgBox "Please allocate a task to the driver before deployment"
Else
Range("F3").Value = Now()
End If
End Sub- Andy ThomsonCopper Contributor
Thank you Lorenzo.
That works perfectly. Your assistance is greatly appreciated.
- Lorenzo KimBronze Contributorglad it helped..