Worksheet_Deactivate error code 1004

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

I wrote the below code so the sheet opens at the bottom row.
VBA Code:
Private Sub Worksheet_Deactivate()
Range("A23358").End(xlUp).Offset(-15, 0).Select
End Sub
I didn't write this as a Worksheet_Activate event because if I did that then the links I've created from other sheets to other rows in this sheet won't run.

I don't know why I get Error 1004 though.

Help appreciated.

Many thanks!
 
I don't use the worksheet_deactivate event code much, but it seems to me that deactivating by activating another tab makes the other tab the activesheet. So, it's no longer possible to selecet any cell on the dectivated sheet the code is written for. You will always get a 1004 error on attempting to do that. Run the simple code below as is and it runs fine. Then uncomment the cell selection line and run it again.
VBA Code:
Private Sub Worksheet_Deactivate()
MsgBox Me.Name & " has been DEACTIVATED"
Range("A1").Value = "DEACTIVATED"
'Range("A1").Select
End Sub
JoeMo,
Thanks for the assist. Like you, I seldom use this code. I was "down in the weeds" trying to detect logic problems with the code, and that basic fact did not occur to me, but it makes perfect sense!
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
@JoeMo yes, your logic makes sense. It's no big deal, I must admit I've always struggled understanding the worksheet_deactivate event.
Many thanks for your help anyway Joe4 and JoeMo
Glad we could help!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,691
Members
449,117
Latest member
Aaagu

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