#1
|
|||
|
|||
If/and in vba
Hi All,
I need to add a line of code that would look at 2 cells A2 and I1 and if both are more than 0 the I want to perform the following conditional formula otherwise do nothing. Code:
Sub IFAND() ' ' IFANDFORM Macro ' 'Can't use the following line of code because it only compares 1 cell Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A2>0" 'Need to add if statment here to because the condition has to be for both A2 and I1 cells if either is blank don't do anything. Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Borders(xlLeft) .LineStyle = xlContinuous .TintAndShade = 0 .Weight = xlThin End With With Selection.FormatConditions(1).Borders(xlRight) .LineStyle = xlContinuous .TintAndShade = 0 .Weight = xlThin End With With Selection.FormatConditions(1).Borders(xlTop) .LineStyle = xlContinuous .TintAndShade = 0 .Weight = xlThin End With With Selection.FormatConditions(1).Borders(xlBottom) .LineStyle = xlContinuous .TintAndShade = 0 .Weight = xlThin End With With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorDark1 .TintAndShade = -0.349986266670736 End With Selection.FormatConditions(1).StopIfTrue = False Range("I3").Select End If End Sub |
#2
|
||||
|
||||
All you need do is change:
Formula1:="=A2>0" to: Formula1:="=(A2>0)*(I1>0)"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|