ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Launching Macro when Cell Changes (https://www.excelbanter.com/excel-programming/387672-launching-macro-when-cell-changes.html)

[email protected]

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 !! ;-) )


Vergel Adriano

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 !! ;-) )



[email protected]

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 !


Vergel Adriano

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 !



Norman Jones

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



Norman Jones

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




All times are GMT +1. The time now is 01:05 PM.

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