Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
Hello there (I'm back with the beginner questions)
Is there a way I could launch macros according to the value of a cell? Being that I want a certain macro to launch if p82 is equal to 1, and a different to launch if p82 is equal to 2, etc... Visual Basic is so frusturating (I wish it were C !! ;-) ) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
maybe something like this. Right click on the tab, then select view code.
Then paste this: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$P$82" Then Select Case Target.Value Case 1 MsgBox "call a macro here" Case 2 MsgBox "call a different macro here" End Select End If End Sub -- Hope that helps. Vergel Adriano " wrote: Hello there (I'm back with the beginner questions) Is there a way I could launch macros according to the value of a cell? Being that I want a certain macro to launch if p82 is equal to 1, and a different to launch if p82 is equal to 2, etc... Visual Basic is so frusturating (I wish it were C !! ;-) ) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
On Apr 18, 2:10 pm, Vergel Adriano
wrote: maybe something like this. Right click on the tab, then select view code. Then paste this: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$P$82" Then Select Case Target.Value Case 1 MsgBox "call a macro here" Case 2 MsgBox "call a different macro here" End Select End If End Sub -- Hope that helps. Vergel Adriano " wrote: Hello there (I'm back with the beginner questions) Is there a way I could launch macros according to the value of a cell? Being that I want a certain macro to launch if p82 is equal to 1, and a different to launch if p82 is equal to 2, etc... Visual Basic is so frusturating (I wish it were C !! ;-) ) That only works if I change it myself...is there a way it could launch the macro when the cell link changes (p82) ? I think it has something to do with the worksheet_calculate but I can't get it. thank you for the quick response ! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
Maybe you can check the value of P82 everytime the worksheet calculates... something like this: Private Sub Worksheet_Calculate() Static vOldValue As Variant With Range("P82") If .Value < vOldValue Then vOldValue = .Value Select Case .Value Case 1 MsgBox "call a macro here" Case 2 MsgBox "call a different macro here" End Select End If End With End Sub -- Hope that helps. Vergel Adriano " wrote: On Apr 18, 2:10 pm, Vergel Adriano wrote: maybe something like this. Right click on the tab, then select view code. Then paste this: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$P$82" Then Select Case Target.Value Case 1 MsgBox "call a macro here" Case 2 MsgBox "call a different macro here" End Select End If End Sub -- Hope that helps. Vergel Adriano " wrote: Hello there (I'm back with the beginner questions) Is there a way I could launch macros according to the value of a cell? Being that I want a certain macro to launch if p82 is equal to 1, and a different to launch if p82 is equal to 2, etc... Visual Basic is so frusturating (I wish it were C !! ;-) ) That only works if I change it myself...is there a way it could launch the macro when the cell link changes (p82) ? I think it has something to do with the worksheet_calculate but I can't get it. thank you for the quick response ! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
Hi Alexdetr,
'---------------- That only works if I change it myself...is there a way it could launch the macro when the cell link changes (p82) ? I think it has something to do with the worksheet_calculate but I can't get it. thank you for the quick response ! '---------------- Try something like: '============= Private Sub Worksheet_Change(ByVal Target As Range) Dim Rng As Range Dim Rng2 As Range Dim Rng3 As Range Set Rng = Me.Range("A1") '<<==== CHANGE On Error Resume Next Set Rng2 = Rng.Precedents On Error GoTo 0 If Not Rng2 Is Nothing Then Set Rng2 = Intersect(Rng2, Target) End If If Not Rng2 Is Nothing Then Select Case Rng.Value Case 1: Call Macro1 Case 2: Call Macro2 Case 3: Call Macro3 End Select End If End Sub '<<============= --- Regards, Norman |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Launching Macro when Cell Changes
Hi Alexdetr,
Set Rng = Me.Range("A1") '<<==== CHANGE I used A1 in my test file but you should change this to P82. --- Regards, Norman |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Launching Macro from Validation List | Excel Programming | |||
Launching Excel macro for every workbook opened. | Excel Programming | |||
Launching macro externally | Excel Programming | |||
Launching a macro by double-clicking on active cell | Excel Programming | |||
launching macro on workbook loading | Excel Programming |