Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-25-2014, 12:14 PM
gbaker gbaker is offline If/and in vba Windows 7 32bit If/and in vba Office 2010 32bit
Competent Performer
If/and in vba
 
Join Date: May 2012
Posts: 111
gbaker is on a distinguished road
Default 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
Thanks in Advance
Reply With Quote
  #2  
Old 09-25-2014, 03:03 PM
macropod's Avatar
macropod macropod is offline If/and in vba Windows 7 64bit If/and in vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All you need do is change:
Formula1:="=A2>0"
to:
Formula1:="=(A2>0)*(I1>0)"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Other Forums: Access Forums

All times are GMT -7. The time now is 01:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft