Hi all
Can someone help me with a piece of conditional format via VBA. It is doing my head in.
Excel somehow changes the input value from my input box - it is simply different to what I select when prompted.
I want to set a conditional format. First I prompt user to select which cell to format, then I prompt to select a cell that contains the value from which the condition is evaluated.
For instance I select G69 is the Cell to be formatted and then A69 as the cell with the value (the value in A69 might change due to other inputs which is why I am doing all this).
Problem is that the conditional format does not look in A69 for the conditional value. I makes it a circular reference to G69. Initially I figured it couldn't work with an .address - but it seems it points at the address. It's just the wrong one as it points to the cell I want to format instead of the cell with conditional value.
Can anyone see what I am doing wrong.
Can someone help me with a piece of conditional format via VBA. It is doing my head in.
Excel somehow changes the input value from my input box - it is simply different to what I select when prompted.
I want to set a conditional format. First I prompt user to select which cell to format, then I prompt to select a cell that contains the value from which the condition is evaluated.
For instance I select G69 is the Cell to be formatted and then A69 as the cell with the value (the value in A69 might change due to other inputs which is why I am doing all this).
Problem is that the conditional format does not look in A69 for the conditional value. I makes it a circular reference to G69. Initially I figured it couldn't work with an .address - but it seems it points at the address. It's just the wrong one as it points to the cell I want to format instead of the cell with conditional value.
Can anyone see what I am doing wrong.
Code:
Sub SelectedRangeStandardValue()
'ActiveSheet.Unprotect Password:="test"
Dim ActSheet As Worksheet
Dim SelRange As Range
Dim Response As Range
Set ActSheet = ActiveSheet
Set SelRange = Selection
Set Response = Selection
Application.DisplayAlerts = False
Set SelRange = Application.InputBox(Prompt:= _
"Choose area", _
Title:="Click area", Type:=8)
' Run the Input Box.
Response = Application.InputBox(Prompt:= _
"Choose standard for format", _
Title:="Click area", Type:=8)
' Check to see if Cancel was pressed.
If Response <> False Then
End If
'clear any lingering formats - just to be sure
SelRange.ClearFormats
'just some recorded macro altered to fit with my inputbox. I have done a similar solution with an integer which works. The response.address points to an address. It is just the wrong one-
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:=Response.Address
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:=Response.Address
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 9223420
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:=Response.Address
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False
'ActiveSheet.Protect Password:="test"
End Sub