ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Conditional Column Display (https://www.excelbanter.com/excel-discussion-misc-queries/195934-conditional-column-display.html)

Shawn Conn

Conditional Column Display
 
I am having trouble trying to figure this one out:

I am having customers fill out a form for me in excel, and am running into
issues with the data they are inputting. I think the best way to correct this
would be to restrict the fields that they can edit.
For instance: If a customer chose 'BI' from the drop down menu in column A,
I want him/her to be able to edit the neighboring cell in column B. Either by
having Column B hidden naturally, and only shown when 'BI' is selected, or
have it shown but can only be edited when 'BI' is selected.

Tim879

Conditional Column Display
 
I wrote the code below recently to do something similar... you could
tweak it to either lock or hide selected cells / columns based on the
user's input.

In summary, whenever the date in C12 is changed, the code determines
whether the change was in the 1st, 2nd or after the 2nd qtr and clears
and (un)locks the input cells accordingly.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$12" Then

If Range("c12").Value < DateSerial(2008, 4, 1) Then
ActiveSheet.Unprotect

' MsgBox "1st q"

Range("c17").ClearContents
Range("c17").Locked = True


Range("c23").ClearContents
Range("c23").Locked = True

ActiveSheet.Protect

ElseIf Range("c12").Value < DateSerial(2008, 7, 1) Then

' MsgBox "2nd q"
ActiveSheet.Unprotect
Range("c17").ClearContents
Range("c17").Locked = False

Range("c23").ClearContents
Range("c23").Locked = True

ActiveSheet.Protect

Else
' MsgBox "3rd or 4th q"
ActiveSheet.Unprotect
Range("c17").ClearContents
Range("c17").Locked = False

Range("c23").ClearContents
Range("c23").Locked = False

ActiveSheet.Protect

End If
End If


End Sub





On Jul 23, 8:41*am, Shawn Conn
wrote:
I am having trouble trying to figure this one out:

I am having customers fill out a form for me in excel, and am running into
issues with the data they are inputting. I think the best way to correct this
would be to restrict the fields that they can edit.
For instance: If a customer chose 'BI' from the drop down menu in column A,
I want him/her to be able to edit the neighboring cell in column B. Either by
having Column B hidden naturally, and only shown when 'BI' is selected, or
have it shown but can only be edited when 'BI' is selected.




All times are GMT +1. The time now is 10:04 AM.

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