Forum Discussion

Andy Thomson's avatar
Andy Thomson
Copper Contributor
Oct 18, 2018
Solved

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 Kim's avatar
    Lorenzo Kim
    Bronze 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

     

Resources