ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Running a macro based on a value (https://www.excelbanter.com/excel-programming/356128-running-macro-based-value.html)

Jeanne Conroy

Running a macro based on a value
 
Is there a way to create an "event based" macro in Excel? I need to have an
input box pop up whenever a cell value greater than 0 is entered.
Thanks!

--



Tom Ogilvy

Running a macro based on a value
 
Use the Change event if it will be entered manually

see Chip Pearson's overview of events
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Jeanne Conroy" wrote:

Is there a way to create an "event based" macro in Excel? I need to have an
input box pop up whenever a cell value greater than 0 is entered.
Thanks!

--




Justin Philips

Running a macro based on a value
 
the only way i can think of to do this is to have it run from the sheet
code (right click select view code)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If cell(x,y).Value 0 Then
macroname
End if

end sub

put that in a loop and that should work.


ron

Running a macro based on a value
 
An appropriately modified version of the following code should do
it...Ron

OnEntry Property and Change Event
An OnEntry handler runs when the user enters data in a worksheet. You
can use the OnEntry property of either the Worksheet or Application
object to associate a procedure with the entry of data on any
worksheet. The event occurs after the user enters data in a cell and
presses ENTER or selects another cell. The event does not occur if the
user click Cut or Paste on the Edit menu or if another procedure
changes the contents of a cell.

For example, the following code associates a procedure that validates
the data entered in a cell with the OnEntry event only if the cell is
in column B:


Sub TrapEntry()
Workbooks("GeneData").Worksheet("GeneCountDB").OnE ntry = _
"ValidateColB"
End Sub
Sub ValidateColB()
With ActiveCell
If .Column = 2 Then ' Test for second column.
If IsNumeric(.Value) Then
If .Value < 0 or .Value 255 Then
Msgbox "Entry must be between 0 and 255."
.Value = ""
End If
Else
' Handle nonnumeric entry.
Msgbox "Entry must be a number between 0 and 255."
.Value = ""
End If
End If
End With
End Sub



All times are GMT +1. The time now is 06:03 PM.

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