E
ExcelMonkey
I have a routine which enables/disables cells based values in other cells.
This is done by callin the enable/disable routines below. Each routine has a
line of code that says:
..Validation.InCellDropdown = False
However this is only relevant if the cell in question has data validation.
I want to wrap of IF logic around this to check to see if the cell has data
validation. I have routine for checking if a cell has data validation (True
False) but it takes a range variable as an argument. I cannot seem to
intigrate it into these two subs.
Does any one know how I would check for this given the code below?
Thanks
'***************************************
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Range("Cell1") = "Static" Then
DisableCell Range("Cell2")
EnableCell Range("Cell3")
Else
EnableCell Range("Cell2")
DisableCell Range("Cell3")
End If
End Sub
'***********************************
Sub DisableCell(ParamArray rng())
Dim i As Long
For i = LBound(rng) To UBound(rng)
With rng(i)
.Interior.Pattern = xlGray50
.Locked = True
.FormulaHidden = False
.Validation.InCellDropdown = False
End With
Next i
End Sub
'***********************************
Sub EnableCell(ParamArray rng())
Dim i As Long
For i = LBound(rng) To UBound(rng)
With rng(i)
.Interior.Pattern = xlSolid
.Locked = False
.FormulaHidden = True
.Validation.InCellDropdown = True
End With
Next i
End Sub
This is done by callin the enable/disable routines below. Each routine has a
line of code that says:
..Validation.InCellDropdown = False
However this is only relevant if the cell in question has data validation.
I want to wrap of IF logic around this to check to see if the cell has data
validation. I have routine for checking if a cell has data validation (True
False) but it takes a range variable as an argument. I cannot seem to
intigrate it into these two subs.
Does any one know how I would check for this given the code below?
Thanks
'***************************************
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Range("Cell1") = "Static" Then
DisableCell Range("Cell2")
EnableCell Range("Cell3")
Else
EnableCell Range("Cell2")
DisableCell Range("Cell3")
End If
End Sub
'***********************************
Sub DisableCell(ParamArray rng())
Dim i As Long
For i = LBound(rng) To UBound(rng)
With rng(i)
.Interior.Pattern = xlGray50
.Locked = True
.FormulaHidden = False
.Validation.InCellDropdown = False
End With
Next i
End Sub
'***********************************
Sub EnableCell(ParamArray rng())
Dim i As Long
For i = LBound(rng) To UBound(rng)
With rng(i)
.Interior.Pattern = xlSolid
.Locked = False
.FormulaHidden = True
.Validation.InCellDropdown = True
End With
Next i
End Sub