Situation I have an excel form and I want to ensure that the user go in a sequence where the next cell will be unlocked only if initial cells are filled up. My excel sheet also has some checkboxes as well as cell merged together.
current solution I am using for example following code:-
If Range("V12").Value > 3 Or Range("V12").Value < 3 Then
Me.Unprotect
Range("E13:G17").Value = ""
Range("E13:G17").Interior.Color = RGB(226, 239, 218)
Range("E13:G17").Locked = True
Me.Protect
Else
Me.Unprotect
Range("E13:G17").Locked = False
Range("E13:G17").Interior.Color = RGB(255, 255, 255)
Me.Protect
but the problem is, I have multiple ranges and I have to write a repeated formula for the remaining ranges.
My requirement Is this the optimal code or I can still improve my code? and I want user to jump only in the green field.
Please find the file through this link:- Link to the excel file,please click here
You have a lot of repeated code which could be reduced significantly if you factor out the Protect/Unprotect into a separate Sub.
Eg:
Would also improve your code to check for a change in (eg) V12 before calling the lock/unlock sub, rather than processing every range regardless of where the Change event was triggered.
EDIT - another approach which should be faster when executing -