Run Macro when criteria is meet

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
732
I have a bunch of VB code in a module. How do i kick off a particular Macro only if a criteria is meet on a sheet for example on a sheet Called Master if Cell B28 has 122 than run a code specific for 122 if it is not 122 than continue with the current code.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try something like this.

Select the Sheet Tab, right mouse button then View Code, change first drop down from Object to Worksheet then add this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("B28") = 122 Then
Call Macro1
Else
'continue code
End If

End Sub
 
Upvote 0
Unfortunitely I can't use this code, Since the Sheet that i am to enter this code is deleted everytime and regenerated.

Here is a portion of the code:

'paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveSheet.Cells(intTopRow, intLHColumn).Select
ActiveSheet.Paste
Application.CutCopyMode = False

PasteValues = True

''''''''RULE ONLY Applies for BA122

'''''''Need code to go Here When rule is meet






ExitFunction:
'return to starting cell
Sheets(strCurrWorksheet).Activate
ActiveSheet.Cells(intCurrRow, intCurrColumn).Select

Exit Sub

ERRORHANDLER:
HandleErrors Err, "PasteValues"
PasteValues = False
GoTo ExitFunction

End Sub


If the rule is meet I want to run this code: Portion of the code.

Sub AuditUpdaterwithnewcombo()
'
' AuditUpdaterwithnewcombo Macro
'

'





Sheets("Audit").Select

' Dim Lastrow As Long


Lastrow = Range("E11").End(xlDown).Row


Range("AK10").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveCell.FormulaR1C1 = "NEW DISTRCHANNEL"
Range("AL10").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveCell.FormulaR1C1 = "Product Type"
Range("AM10").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveCell.FormulaR1C1 = "Combo"

'Formual for NeW dist Channel
 
Upvote 0
If you can't use the sheet code then perhaps look behind the workbook code. There is an option that deals with SheetCalculate

Open VBA then on the left below each worksheet name you will see thisWorkBook double click then change the first drop down from Object to Workbook then the right right drop down change to SheetCalculate. YOu will then get this

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
End Sub

Try specifiying the sheetname and cell and what you want to happen here.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,856
Members
452,948
Latest member
UsmanAli786

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