macro

juan1

New Member
Joined
May 17, 2017
Messages
46
how do I change the below to not be an event, but run from a macro1?
thanks
Jan

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInt As Range
Dim rCell As Range

'change the input cell range as desired

Set rInt = Intersect(Target, Range("plus20pct"))
If Not rInt Is Nothing Then
For Each rCell In rInt
If IsNumeric(rCell) Then
With Application
.EnableEvents = False
rCell = rCell * 1.2
.EnableEvents = True
End With
End If
Next
End If
End Sub
 
Is there a way to run a macro that says don't run the event macro if I chose not to do the multiplication in the cell?
thanks
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In that case you'd still need to use worksheet_change, try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Application.EnableEvents = False 'Turn off events so changes to cell don't retrigger event
Application.Calculation = xlCalculationManual
    Dim KeyCells As Range
    Set KeyCells = Range("A1:D6")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then




     If IsNumeric(Target.Value) And Not IsEmpty(Target.Value) Then Target.Value = Target.Value * 1.2
       
    End If
    Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
Try this then if you want yes no options

Code:
Private Sub Worksheet_Change(ByVal Target As Range) 
Application.EnableEvents = False 'Turn off events so changes to cell don't retrigger event
Application.Calculation = xlCalculationManual
    Dim KeyCells As Range
    Dim answer As Integer
    Set KeyCells = Range("A1:D6")
    
 
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing And IsNumeric(Target.Value) And Not IsEmpty(Target.Value) Then


   answer = MsgBox("Multiply number?", vbYesNo + vbQuestion)
   If answer = vbYes Then
     Target.Value = Target.Value * 1.2
Else
    'do nothing
End If
     
    
       
    End If
    Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top