Data Validation

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
I have a simple macro that hides a few rows. When those rows are hidden, I need a way to restrict any data entry until those rows have been unhidden. I am thinking data validation, but I have no idea how I would make that work.

When rows 16:17 are hidden, I need to restrict any entry in cells D12:O15

Any ideas would be greatly appreciated.

Andrew
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Andrew,

Perhaps something like this......

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A16:A17").EntireRow.Hidden = False Then Exit Sub
If Intersect(Target, Range("D12:O15")) Is Nothing Then Exit Sub
MsgBox "Restricted Data Entry"  edit to suit or remove
Range("A1").Select  ' edit to suit
End Sub

Hope that helps.
 
Upvote 0
Andrew,

Another thought

If you do not have any conflicting issues with protecting the sheet in any way then perhaps something like this code which will toggle the hiding and unhiding or rows 16 & 17 and will lock / unlock and protect cells D12:O1
If no other cells are to be locked then select all cells and unlock before running the code. Make sure you start with rows not hidden and cells not locked before you run code.

Code:
Sub HuHRows()
ActiveSheet.Unprotect
Range("A16:A17").EntireRow.Hidden = Not Range("A16:A17").EntireRow.Hidden
Range("D12:O15").Locked = Not Range("D12:O15").Locked
ActiveSheet.Protect
End Sub

Also note that you cannot have both these code enabled at the same time!!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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