0

i have a shipment tracking table with many records, each represent a shipment and in a different sheet i have an "Arrival Notification" template , with a command button to update template values and send automatic email to client once their shipment arrives

back to the table, column "Z" has the shipment arrival date column "AH" for the arrival notification .. it can have 2 values only (SEND, SENT) .. SEND for shipments with no notification sent yet , and SENT for notifications already sent

WHAT I WANT IS : for each cell in col "AH" with the value "SEND" only, once clicked to run the code CommandButton1_Click from the second sheet and then change cell value to "SENT"

*what i did was as below , but not working

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column = Range("AH1").Column Then
Call CommandButton1_Click
Else
Range("AH" & Target.Row).Value = "SENT"
  End If
End Sub

1 Answers1

0

First, find the SelectionChange event for the Worksheet (this is important, as you cannot just place this code anywhere... it has to be in that event.

Then paste this code into it.

If Target.Column = 26 Then ' column Z
  CommandButton1_Click
  Range("AH" & Target.Row).Value = "SENT"
End If

When you are done, it should look like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Column = 26 Then ' column Z
    CommandButton1_Click
    Range("AH" & Target.Row).Value = "SENT"
  End If
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33