PC Review


Reply
Thread Tools Rate Thread

Conditional Format formula using VBA

 
 
Robert H
Guest
Posts: n/a
 
      11th Dec 2008
I need help setting up a Conditional Format formula using VBA.
Currently I fill a lot of rows of data with a simple formula using
this code:
There are several versions of this code in the module, each one
covering a unique data type ‘QD indicates the data type.

Sub condFormatingDEV()

'QD
Dim qdNm As Name
Dim qdNmRng As Range
Dim qdNmRngA As Range
Dim qdNmRngB As Range
Dim qdNmRngC As Range

For Each qdNm In ActiveSheet.Names ' Iterate through each
element.
On Error Resume Next
Set qdNmRngB = qdNm.RefersToRange
On Error GoTo 0
If Not qdNmRngB Is Nothing Then
Set qdNmRngA = Cells.Find(what:="QD", _
After:=ActiveCell, _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

On Error Resume Next
If Not qdNmRngA Is Nothing Then
Range(qdNmRngA).Select
Selection.FormatConditions.Delete

'UCL
Selection.FormatConditions.Add
Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="=" & Selection.End
(xlDown).Offset(11, 0).Address
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Strikethrough = False
End With
Selection.FormatConditions
(1).Interior.ColorIndex = 22

End If
End If
Next

End Sub

The end result is a formula like =$K$76. The criteria is in the same
column but a few spaces below so the offset command work nicely.
Now I have two criteria that can be used dependant on the value of a
cell in the same row. The cell in the row is always in column “C”
which has a heading of “Type”.

Manually entering the formula in the Conditional Format wizard I enter
"=IF($C5="HL",K$25,$K$22)". Then copy/paste in to the remaining cells
in the column using the format painter. I also copy/paste the formats
to any other column that contains QD data and that works as well. No
I want to build the formula using VBA

Locating the two criteria’s can be done as I did before using
Selection.End(xlDown).Offset(#, 0) .address twice. How do I do I call
out column C of the current row?

Thanks
Robert
 
Reply With Quote
 
 
 
 
Robert H
Guest
Posts: n/a
 
      11th Dec 2008
For what its worth I hashed out the easy part of the formula but still
need to replace "C5" with something that references the intersection
of column C with the current row.


Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater,
_
Formula1:="=IF(" & "C5" & "=" & """HL"""
& "," & _
Selection.End(xlDown).Offset(17,
0).Address _
& "," & _
Selection.End(xlDown).Offset(14,
0).Address _
& ")"

With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Strikethrough = False
End With
Selection.FormatConditions
(1).Interior.ColorIndex = 22
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional format formula dzelnio Microsoft Excel Misc 3 22nd Aug 2007 05:52 PM
Multiple conditional on conditional format formula Frank Kabel Microsoft Excel Programming 1 27th Jul 2004 06:24 PM
Re: Multiple conditional on conditional format formula Bob Phillips Microsoft Excel Programming 0 27th Jul 2004 05:30 PM
Conditional format formula JEM Microsoft Excel Discussion 4 16th Apr 2004 03:39 AM
conditional format formula? help please Geoff Brandt Microsoft Excel Discussion 2 29th Sep 2003 11:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 AM.