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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Just remove the line

Private Sub Worksheet_Change(ByVal Target As Range)

and replace it with

Code:
[COLOR=#333333]Sub macro1
[/COLOR][COLOR=#333333]Dim rInt As Range[/COLOR]
[COLOR=#333333]Dim rCell As Range[/COLOR]

[COLOR=#333333]'change the input cell range as desired[/COLOR]

[COLOR=#333333]Set rInt = Intersect(Target, Range("plus20pct"))[/COLOR]
[COLOR=#333333]If Not rInt Is Nothing Then[/COLOR]
[COLOR=#333333]For Each rCell In rInt[/COLOR]
[COLOR=#333333]If IsNumeric(rCell) Then[/COLOR]
[COLOR=#333333]With Application[/COLOR]
[COLOR=#333333].EnableEvents = False[/COLOR]
[COLOR=#333333]rCell = rCell * 1.2[/COLOR]
[COLOR=#333333].EnableEvents = True[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]Next[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End Sub[/COLOR]

You can also stick it in a module rather than under a worksheet object
 
Last edited:
Upvote 0
Code:
[COLOR=#333333]Sub Macro1[/COLOR]
[COLOR=#333333]Dim rInt As Range[/COLOR]
[COLOR=#333333]Dim rCell As Range[/COLOR]

[COLOR=#333333]'change the input cell range as desired[/COLOR]

[COLOR=#333333]Set rInt = Range("plus20pct"))[/COLOR]
[COLOR=#333333]If Not rInt Is Nothing Then[/COLOR]
[COLOR=#333333]  For Each rCell In rInt[/COLOR]
[COLOR=#333333]     If IsNumeric(rCell) Then [/COLOR][COLOR=#333333]rCell = rCell * 1.2[/COLOR]
[COLOR=#333333]  Next[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End Sub
[/COLOR]
 
Upvote 0
tried that but get an error on this line

Set rInt = Intersect(Target, Range("plus20pct"))
 
Upvote 0
Like this:
Code:
Sub MutlipyByOnePointTwo()
Dim rCell As Range
For Each rCell In Range("plus20pct")
    If IsNumeric(rCell) Then rCell = rCell * 1.2
Next rCell
End Sub
 
Upvote 0
Replace:

Range("plus20pct")

with:

Range("A1:D6")
 
Upvote 0
Are you just tryng to multiply any numbers in the range by 1.2? If so this should be OK

Code:
Sub MutlipyByOnePointTwo()


    Dim rCell As Range
    Dim rRng As Range


    Set rRng = Range("A1:D6")


    For Each rCell In rRng.Cells
        If IsNumeric(rCell) And Not IsEmpty(rCell) Then rCell = rCell * 1.2
    Next rCell


End Sub
 
Last edited:
Upvote 0
yes, but I want to run the macro then and only then any time I enter in those cells the multiplication happens. Not the existing cells that already have an input.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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