Help with Deactivate

imback2nite

Board Regular
Joined
Oct 30, 2004
Messages
211
Office Version
  1. 2003 or older
Platform
  1. Windows
I'm having trouble with the Deactivate. The code works now but it keeps taking me back to the original page and not the page the user is trying to select. I'm probably doing something dumb but I can't figure it out. Thanks for any help!


Code:
Private Sub Worksheet_Deactivate()
    Sheet5.Select
    Sheet5.Unprotect "4wink"
    Range("I1:I500").Select
    Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Sheet5.Range("D1:D500").Select
    Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Sheet5.Range("E2:E500").ClearContents
    Sheet5.Range("E2") = "=IF(D2="""","""",COUNTIF(Galleys!$B$21:$AS$65,D2)+SUMPRODUCT((Galleys!$B$20:$AS$20=""LARGE"")*(Galleys!$B$21:$AS$65=D2)))"
    Sheet5.Range("E2").Select
    Selection.AutoFill Destination:=Range("E2:E" & Cells(Rows.Count, "D").End(xlUp).Row)
    Sheet2.CommandButton1.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A2")
    Sheet2.CommandButton3.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A3")
    Sheet2.CommandButton4.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A4")
    Sheet2.CommandButton2.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A5")
    Sheet2.CommandButton6.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A6")
    Sheet2.CommandButton7.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A7")
    Sheet2.CommandButton11.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A8")
        Application.CutCopyMode = False
            ActiveSheet.Protect "4wink"
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Its because you select another sheet in the first line. See if this does as intended

Code:
Application.ScreenUpdating = False

With Sheet5
    .Unprotect "4wink"
    .Range("I1:I500").Sort Key1:=.Range("I2"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    .Range("D1:D500").Sort Key1:=.Range("D2"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    .Range("E2:E500").ClearContents
    .Range("E2") = "=IF(D2="""","""",COUNTIF(Galleys!$B$21:$AS$65,D2)+SUMPRODUCT((Galleys!$B$20:$AS$20=""LARGE"")*(Galleys!$B$21:$AS$65=D2)))"
    .Range("E2").AutoFill Destination:=.Range("E2:E" & .Cells(.Rows.Count, "D").End(xlUp).Row)
End With

With Sheet2
    .CommandButton1.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A2")
    .CommandButton3.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A3")
    .CommandButton4.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A4")
    .CommandButton2.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A5")
    .CommandButton6.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A6")
    .CommandButton7.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A7")
    .CommandButton11.Caption = ThisWorkbook.Sheets("Disciplines").Range("$A8")
End With
        
Application.CutCopyMode = False
Sheet5.Protect "4wink"

Application.ScreenUpdating = True
 
Upvote 0
Steve! That was it! Thank you soo much! I really like the ...'With'! Just shows how much I need to learn. You make it look so easy!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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