modify code to run another code if need

alan myers

Board Regular
Joined
Oct 31, 2017
Messages
119
Office Version
  1. 365
Platform
  1. Windows
win you run this code I need to check input sheet (j2) if it = NY then run tuenojh macro else continue with this
code


Sub tuesday()
'
' tuesday Macro
'
Worksheets("INPUT").Activate
'
Cells.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Font
.FontStyle = "Bold"
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.ColumnWidth = 10
Selection.RowHeight = 15
Rows("1:1").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=15
Rows("23:24").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=24
Rows("46:46").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=24
Rows("69:69").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=21
Rows("92:92").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=24
Rows("115:115").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=18
Rows("138:139").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-141
Range("B1:N22").Select
Range("N22").Activate
Selection.Cut
Range("A1").Select
ActiveSheet.Paste
Columns("F:F").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
ActiveSheet.Shapes.Range(Array("Shape 2")).Select
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Range("C1").Select
ActiveCell.FormulaR1C1 = "bh"
Range("D1").Select
ActiveCell.FormulaR1C1 = "ih"
Range("E1").Select
ActiveCell.FormulaR1C1 = "ii"
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Range("I1").Select
ActiveCell.FormulaR1C1 = "tv"
Range("K1").Select
ActiveCell.FormulaR1C1 = "sun is"
Range("L1").Select
ActiveCell.FormulaR1C1 = "sun ny"
Range("C2").Select
ActiveCell.FormulaR1C1 = "0"
Range("D2").Select
ActiveCell.FormulaR1C1 = "0"
Range("E2").Select
ActiveCell.FormulaR1C1 = "0"
Range("I2").Select
ActiveCell.FormulaR1C1 = "0"
Range("K2").Select
ActiveCell.FormulaR1C1 = "0"
Range("L2").Select
ActiveCell.FormulaR1C1 = "0"
Range("K1:L2").Select
Range("K2").Activate
Range("K2:L2").Select
Selection.AutoFill Destination:=Range("K2:L56"), Type:=xlFillDefault
Range("K2:L56").Select
ActiveWindow.SmallScroll Down:=12
Selection.AutoFill Destination:=Range("K2:L137"), Type:=xlFillDefault
Range("K2:L137").Select
ActiveWindow.SmallScroll Down:=-162
Range("I2").Select
Selection.AutoFill Destination:=Range("I2:I137"), Type:=xlFillDefault
Range("I2:I137").Select
ActiveWindow.SmallScroll Down:=-150
Range("C2:E2").Select
Selection.AutoFill Destination:=Range("C2:E23"), Type:=xlFillDefault
Range("C2:E23").Select
ActiveWindow.SmallScroll Down:=18
Selection.AutoFill Destination:=Range("C2:E137"), Type:=xlFillDefault
Range("C2:E137").Select
ActiveWindow.SmallScroll Down:=-141
Range("I13").Select
ActiveWindow.SmallScroll Down:=-24
Cells.Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Range("I9").Select
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Add these four lines of code to your macro:
VBA Code:
Sub tuesday()
    '
    ' tuesday Macro
    '
    If Range("J2") <> "NY" Then                   '<- added
        Worksheets("INPUT").Activate
        '
        Cells.Select
        With Selection
    '
    ' all the rest of your code
    '
        End With
        Range("I9").Select
    Else                                          '<- added
        Call tuenojh                              '<- added
    End If                                        '<- added
End Sub
 
Upvote 0
You do understand when you run this line of code it means do this to all 5 billion or so cells in this worksheet.

Cells.Select

Do you really need to do this on all the cells in your workbook?
 
Upvote 0
I DONT KNOW WHAT YOU ARE DOING WHEN I RUN THIS CODE I NEED TO STOP AND CHECK (J2) ON THE INPUT SHEET IF IT IS NY
THEN STOP THIS CONE AN RUN TUESDAYNOJH MACRO INSTEAD
IF IT IS NOT NY CUNTION RUNNING THE CODE
 
Upvote 0
Forget what I suggested in my post #3 and add these four lines of code (almost the same as before) to your macro where you need to stop to check J2.
VBA Code:
If Sheets("input").Range("J2") = "NY" Then
    Call TUESDAYNOJH
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,688
Members
448,978
Latest member
rrauni

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