ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   After Entry - Lock and Go to Certain Cell (https://www.excelbanter.com/excel-programming/336304-after-entry-lock-go-certain-cell.html)

Paige

After Entry - Lock and Go to Certain Cell
 
On my worksheet, if a user answers 'Yes' to cell C42, then I want to unhide
rows 43:48 and go to Cell C43 (the next unlocked cell); if they answer 'No'
in cell C42, I want to hide and lock rows 43:48 and go to Cell C52 (which is
the next unlocked cell after C48 assuming rows 43:48 are locked). Below is
the code I have, but only part of it works.....if 'No' - it works fine; if
the answer is 'Yes', the code does unhide rows 43:48, but takes the user to
C52, instead of C43. I've tried 'select' and 'activate', but can't use
because once 'yes' is entered in C42, they can't get back to C42 to change it
back to 'no' if they want to. Can someone advise what I need to do to get
the 'yes' portion working correctly?

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("C42").Value = "No" Then
ActiveSheet.Unprotect
Rows("43:48").Locked = True
Rows("43:48").Hidden = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End If

If Range("C42").Value = "Yes" Then
ActiveSheet.Unprotect
Rows("43:48").Hidden = False
Range("C43:K48").Locked = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

End If
End Sub


All times are GMT +1. The time now is 10:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com