Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Launching Macro from Validation List RJB Excel Programming 9 October 27th 08 09:46 PM
Launching Excel macro for every workbook opened. AbsoluteZero Excel Programming 1 December 15th 05 06:21 PM
Launching macro externally erikcw Excel Programming 1 November 14th 05 03:14 PM
Launching a macro by double-clicking on active cell aca Excel Programming 5 August 4th 05 10:08 PM
launching macro on workbook loading Ric[_2_] Excel Programming 4 October 29th 03 04:57 AM


All times are GMT +1. The time now is 04:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"