ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Run a macro if a certain value is entered in a cell (https://www.excelbanter.com/excel-worksheet-functions/70160-run-macro-if-certain-value-entered-cell.html)

nickystan

Run a macro if a certain value is entered in a cell
 
Hi,
I want to have it so that on a column if a certain value is entered in any
of the cells then a message is displayed to tell them to do something else.
I want to be able to run a macro if the value is entered.

Dave Peterson

Run a macro if a certain value is entered in a cell
 
You can use a worksheet event ...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub

MsgBox "You just changed: " & Target.Address(0, 0) & vbLf & _
". Now don't forget to..."

End Sub

Right click on the worksheet tab that should have this behavior. Select view
code and paste this into the code window that just opened.

Change A1 to the address of the cell you want to check.

nickystan wrote:

Hi,
I want to have it so that on a column if a certain value is entered in any
of the cells then a message is displayed to tell them to do something else.
I want to be able to run a macro if the value is entered.


--

Dave Peterson

nickystan

Run a macro if a certain value is entered in a cell
 
Thanks - that was really helpful

"Dave Peterson" wrote:

You can use a worksheet event ...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub

MsgBox "You just changed: " & Target.Address(0, 0) & vbLf & _
". Now don't forget to..."

End Sub

Right click on the worksheet tab that should have this behavior. Select view
code and paste this into the code window that just opened.

Change A1 to the address of the cell you want to check.

nickystan wrote:

Hi,
I want to have it so that on a column if a certain value is entered in any
of the cells then a message is displayed to tell them to do something else.
I want to be able to run a macro if the value is entered.


--

Dave Peterson



All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com