Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default VBA Excel Conditional Formatting <--rookie here

You're wekcome.

Be careful with the count usage, it is convenient to get to the last row or
column, but sometimes, if used in a loop, or for adding formulae to cells, it
can add large overheads to running times (for loops) or file sizes (when
adding a formula). In these cases you should look for alternative methods so
that you only process the required number of rows or columns. As you will
find, using the conditional formatting for the entire column does not
generate excessive overheads, the file size won't alter much.

Keep playing with it, I'm sure you'll have much fun.

(please remember to click yes if replies you receive are helpful to you)




"Dan" wrote:

On Dec 12, 5:23 pm, SeanC UK
wrote:
Hi Dan,

Try this, it should work for the formatting conditions you require from cell
A5 to the bottom of column A.

Public Sub MyConditionalFormatting()
Range(Cells(5, 1), Cells(Rows.Count, 1)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$A5$B5"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$A5<$B5"
Selection.FormatConditions(2).Interior.ColorIndex = 4
End Sub

As a rookie I would suggest using the Record Macro facility to see roughly
how it happens when you manually enter such code, and build up from there.
Although this won't always give you the exact results you desire, it is a
good starting place for syntax and object names, methods and properties.

The code above should appear from a recorded macro, but I have amended the
code because you might find that a $ appears before the row numbers when you
click a cell to build the formatting formula. If this happens then all the
cells from A5 down would react on the contents of A5 and B5 only. Removing
that $ and running the code means that on subsequent rows the row number is
incremented, so that A6 reacts to the contents of cells A6 and B6.

The second line, with the Delete in it, means that any existing conditional
formats are removed, otherwise you might run into a problem with a max of 3
in Excel 11 and earlier versions. I can't remember the limits of Excel 12 off
the top of my head.

The first line simply selects the cells from A5 to the last row in column A.

The remaining line are self explanatory, they just add the rules and
conditions.

I would just point out that you haven't included A5=B5 in your conditions,
in case you meant to.

Hope this helps,

Sean.

--
(please remember to click yes if replies you receive are helpful to you)



"Dan" wrote:
Hello -


I would like to use VBA for some Condtional Formatting.


I have 2 columns, A and B. From row 5 down, I would like to have
cells in column A be Conditional Formatted.


For example:
* If A5B5 then color RED
* If B5<A5 then color GREEN
* ...and so on till the end of data in Column A.


Thanks for any assistance.
Dan- Hide quoted text -


- Show quoted text -


Great write-up, thanks Sean. I did try the "record" macro to try and
learn, but I used a copy and paste method to get the row to highlight
and got a little confused from there. I like how you use the Count
function in your code.

Regards,
Dan

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
Conditional Formatting in Excel Brian New Users to Excel 4 December 10th 09 08:40 PM
Excel Rookie Question Ron Excel Programming 5 February 24th 06 05:52 PM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM
Excel VBA - Conditional formatting cata_and[_3_] Excel Programming 2 June 4th 04 01:21 PM
rookie needs help with replace formatting and case change Jim[_45_] Excel Programming 12 May 1st 04 11:29 AM


All times are GMT +1. The time now is 06:38 PM.

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

About Us

"It's about Microsoft Excel"