macro

N

naeemsbp

Dear

Ihave macro below i want to run this when i enter data in cell "D10"
please help

Sub macro2()

Dim varAnswer As String
varAnswer = MsgBox("please insure that all data is i
thousands?", vbYesNo, "Warning")
If varAnswer = vbNo Then
Exit Sub
End If


End Sub
 
S

Simon Lloyd

Put this in the worksheet code module

*Private Sub Worksheet_Change(ByVal Target As Range)
If target.cells.count >1 then exit su
If Not Intersect(Target, Range("D10")) Is Nothing The
MsgBox "This is" & Target.Addres
'Call Macro2 ''uncomment this to run your cod
End I
*End Sub

--
Simon Lloy

Regards
Simon Lloy
'The Code Cage' (http://www.thecodecage.com
 
D

Daryl - Honeywell

I have a similar issue. I want to run one of my macros based on conditional
results of a formula. For example, if cell XXXX is TRUE, then run macro,
else don't. I was searching help file, but I can't see refernce to VB code
that will run based on cell value or a formula that I can enter to activate
said macro. Help please....

Thanks,
Daryl Balcom
Honeywell
 
D

Daryl - Honeywell

Thanks. I tried to do that (actually using D10) and it wouldn't call my
macro when I entered something in the cell. The macro works independently,
but not through the code you provided. I added it to the VB code of my macro.
I just made a silly macro to try out the function:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.count > 1 Then Exit Sub
If Not Intersect(Target, Range("D10")) Is Nothing Then
MsgBox "This is" & Target.Address
Call TEST
End If
End Sub


Sub TEST()
'
' TEST Macro
' Macro recorded 11/26/2008 by Honeywell
'

'
Range("E1").Select
ActiveCell.FormulaR1C1 = "TEST"
Range("E2").Select
End Sub
 
G

Gord Dibben

Your posted code works for me when I change D10.

But if D10 is a calcualted value of TRUE or FALSE you need a calculate
event, not a change event.

Private Sub Worksheet_Calculate()
If Me.Range("D10").Value = -1 Then '-1 is TRUE, 0 is FALSE
Call TEST
End If
End Sub

Sub TEST()
'
' TEST Macro
' Macro recorded 11/26/2008 by Honeywell
'

'
Range("E1").Select
ActiveCell.FormulaR1C1 = "TEST"
Range("E2").Select
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top