Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Conditional Format formula using VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Conditional Format formula using VBA

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Conditional Format Formula David K. Excel Worksheet Functions 6 May 4th 10 03:46 AM
conditional format with formula snax500 Excel Discussion (Misc queries) 1 September 29th 08 05:50 PM
Conditional format formula Shu of AZ Excel Discussion (Misc queries) 1 November 26th 06 07:27 PM
Multiple conditional on conditional format formula Frank Kabel Excel Programming 1 July 27th 04 06:24 PM
Multiple conditional on conditional format formula Bob Phillips[_7_] Excel Programming 0 July 27th 04 05:30 PM


All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"