Run a Macro when value is...

Closed
cprevoisin Posts 3 Registration date Thursday September 5, 2013 Status Member Last seen September 6, 2013 - Sep 5, 2013 at 03:11 PM
 Blocked Profile - Sep 6, 2013 at 07:30 PM
Hello! I have been trying to run a Macro within a worksheet. Running the macro depends on the value of a cell, it can be 6 or 4 (Changes depending on a calculation). If its 4, I need to run MacroA, and if its 6, I need to Run MacroB.

I know that I need to go to the Visual Basic but can't figure out the lines! Can someone help me please!!!!

3 responses

Blocked Profile
Sep 5, 2013 at 03:22 PM
Good Afternoon,

Insert this when the workbook sheet is changed:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim valueX
valueX = Sheet1.Range("A4")
If valueX = "4" Then
MsgBox ("your macro a here")
Else
MsgBox ("your macro b here")
End If


End Sub

Have Fun!
cprevoisin Posts 3 Registration date Thursday September 5, 2013 Status Member Last seen September 6, 2013
Sep 5, 2013 at 08:05 PM
Thank you very much! But I still have a problem. The macro wont run...?! Do I need to make something else so it knows the value in the cell changed?

Also, is it possible to do this?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim valueX
valueX = Sheet1.Range(AQ4)
If valueX = "4" Then
MsgBox (AlturaA)
Else
Dim valueX
valueX = Sheet1.Range(AQ4)
If valueX = "6" Then
MsgBox (AlturaB)
End If

This is because I need the Macros to work with the two different values...
Thank you very much for your help!
Blocked Profile
Sep 6, 2013 at 08:39 AM
It works on my sheet. :( Did you save it as a Macro Enabled Sheet? You have to save it as Macro enabled. Good luck!
0
cprevoisin Posts 3 Registration date Thursday September 5, 2013 Status Member Last seen September 6, 2013
Sep 6, 2013 at 04:43 PM
How do i save it that way? It doesn't gives me an option.:(
Blocked Profile
Sep 6, 2013 at 07:30 PM
Go to file...Save As...

In the file type...there is a drop down tab.....select "Macro Enabled".

What Version?
0