Code Not Be Applied To Correct Worksheet

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am having an issue here with my sub commands being applied to the correct worksheet.

Rich (BB code):
Worksheets.Add(After:=Worksheets(13)).Name = "WPL"
        Worksheets.Add(After:=Worksheets(13)).Name = "CUE"
        
        '** POPULATE WORKSHEETS
        
        .Range("H12") = "Groom"
        .Range("I12") = "Prepare"
        .Range("J12") = "Signature"
        .Range("K12") = "Lights On"
        .Range("L12") = "Lights Off"
        .Range("M12") = "1"
        .Range("N12") = "2"
        .Range("O12") = "3"
        .Range("P12") = "4"
        .Range("Q12") = "Close"
        
        If .FilterMode Then .ShowAllData
        llastrow = .Range("R" & Rows.Count).End(xlUp).Row
        
        'WPL
        wshvar.Range("I27") = Worksheets("Staff").Range("B10")
        With .Range("A12:R" & llastrow)
            .AdvancedFilter _
                Action:=xlFilterInPlace, _
                CriteriaRange:=wshvar.Range("I28:R38"), _
                Unique:=False
            On Error Resume Next
        End With
        Worksheets("MasterWKSH").Range("A1:R300").Copy
        
        With Worksheets("WPL")
            With Range("A1")
                .PasteSpecial xlPasteColumnWidths
                .PasteSpecial xlPasteAll
            End With
            llastrow = .Range("R" & Rows.Count).End(xlUp).Row
            
            .Range("M1") = Format(wshcore.Range("B2"), "dddd, mmmm dd, yyyy")
            .Range("M4") = wshvar.Range("I27")
            .Range("L4") = Application.VLookup(.Range("K4"), wshstaff.Range("L4:M20"), 2, False)
            .Range("P4") = Application.VLookup("WPL1", wshcore.Range("BA:DJ"), 58, False)
            .Range("M5") = Format(Application.VLookup("WPL1", wshcore.Range("BA:DJ"), 61, False), "h:mmA/P") & " - " & Format(Application.VLookup("WPL1", wshcore.Range("BA:DJ"), 62, False), "h:mmA/P")
            .Range("P5") = Application.VLookup("WPL1", wshcore.Range("BA:DJ"), 59, False) & "-" & Application.VLookup("WPL1", wshcore.Range("BA:DJ"), 60, False)
            
            With Range("H13:Q" & llastrow)
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
                    Formula1:="=varhold!$I$27"
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                With .FormatConditions(1).Interior
                    .PatternColorIndex = xlAutomatic
                    .ThemeColor = xlThemeColorLight1
                    .TintAndShade = 0.499984740745262
                End With
                .FormatConditions(1).StopIfTrue = False
                .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
                    Formula1:="=varhold!$I$27"
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                With .FormatConditions(1).Font
                    .ThemeColor = xlThemeColorDark1
                    .TintAndShade = 0
                End With
                .FormatConditions(1).StopIfTrue = False
            End With

The code in green adds two new worksheets to my workbook. CUE and WPL
Oddly ... despite the code 'With Worksheets("WPL")' , the code in red is performed on worksheet CUE, while the code in blue, is performed in worksheet WPL.

If I don't add worksheet CUE to the workbook, it works.

Is anyone able to spot where I've messed up?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Inside a With ... End With construct you need the dot qualifier to specify that properties/methods should apply to the object, eg:

Rich (BB code):
With Worksheets("WPL")
    With .Range("A1")

 
Upvote 0
Thanks guys! Darn periods! Sometimes a second set of eyes really helps!
Mission accomplished.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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