LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default visual basic conditional formatting produces strange results

Hi, I'm trying to put together a piece of code that will generate conditional
formatting for cells in a worksheet. The formatting should alter the colour
of the cell based on values held in a range of cells beneath. In order for
the user to be able to add/delete rows in this range, R1C1 style won't work
as it doesn't give me relative references. Here's the code I've put together
as a test, but rather than generate formula for column A for the cells
immediately below the one formatting is to be applied to, it uses cell ranges
from other parts of the spreadsheet that I don't reference. Can anyone help
please?

Sub ColumnNo()

sectionrow = 2
colval = 1
rowval = 7
col_letter = "A"

Do Until sectionrow 20

With Workbooks("create master board").Sheets("sheet3").Cells(sectionrow,
colval)

first_spread = sectionrow + 1

.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=and(countblank(" & col_letter & first_spread & ":" &
col_letter & rowval & ")=0,countif(" _
& col_letter & first_spread & ":" & col_letter & rowval & ",""""& " &
col_letter & sectionrow & ")=0)"
.FormatConditions(1).Interior.ColorIndex = 35

End With

sectionrow = rowval + 1
rowval = sectionrow + 5

Loop
End Sub
 
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
Visual Basic Help - Pivot table, formatting colors PJS Excel Discussion (Misc queries) 0 July 14th 06 01:41 AM
visual basic conditional formatting produces strange results Carl[_3_] Excel Programming 0 January 25th 06 08:30 AM
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic/ Macro date formatting in Excel 97 Frank[_19_] Excel Programming 3 April 13th 04 11:04 AM


All times are GMT +1. The time now is 03:03 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"