Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Execl 2000:
We have a workbook with a worksheet that can have a varying number of rows. The last 5 rows however will always have data like the following. A B C 51 Total 70 52 53 Test1 20 54 Test2 75 55 Test3 5 We want the macro to compare the number in B53 to B51. If B53 is greated than B51, we want A53 and B53 to be formatted with a green fill color. If B54 is greater than B51, we want A54 and B54 to have a yellow fill. Otherwise we want A55 and B55 to be red. We don't know how to get this to work because the number of rows will always be different when we run the macro. Appreciate any assistance. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dim rng as Range
set rng = columns(1).Find("Total") if not rng is nothing then if rng.offset(2,1) rng.offset(0,1) then rng.offset(2,0).Resize(1,2).Interior.ColorIndex = 4 elseif rng.offset(3,1) rng.offset(0,1) then rng.offset(3,0).Resize(1,2).Interior.ColorIndex = 6 else rng.offset(4,0).Resize(1,2).Interior.ColorIndex = 3 End if -- regards, Tom Ogilvy "Ken" wrote in message ... Execl 2000: We have a workbook with a worksheet that can have a varying number of rows. The last 5 rows however will always have data like the following. A B C 51 Total 70 52 53 Test1 20 54 Test2 75 55 Test3 5 We want the macro to compare the number in B53 to B51. If B53 is greated than B51, we want A53 and B53 to be formatted with a green fill color. If B54 is greater than B51, we want A54 and B54 to have a yellow fill. Otherwise we want A55 and B55 to be red. We don't know how to get this to work because the number of rows will always be different when we run the macro. Appreciate any assistance. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Tom. It works perfectly!
(I did have to add a last "End if" line of code.) -----Original Message----- Dim rng as Range set rng = columns(1).Find("Total") if not rng is nothing then if rng.offset(2,1) rng.offset(0,1) then rng.offset(2,0).Resize(1,2).Interior.ColorIndex = 4 elseif rng.offset(3,1) rng.offset(0,1) then rng.offset(3,0).Resize(1,2).Interior.ColorIndex = 6 else rng.offset(4,0).Resize(1,2).Interior.ColorIndex = 3 End if -- regards, Tom Ogilvy "Ken" wrote in message ... Execl 2000: We have a workbook with a worksheet that can have a varying number of rows. The last 5 rows however will always have data like the following. A B C 51 Total 70 52 53 Test1 20 54 Test2 75 55 Test3 5 We want the macro to compare the number in B53 to B51. If B53 is greated than B51, we want A53 and B53 to be formatted with a green fill color. If B54 is greater than B51, we want A54 and B54 to have a yellow fill. Otherwise we want A55 and B55 to be red. We don't know how to get this to work because the number of rows will always be different when we run the macro. Appreciate any assistance. . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes, sorry - didn't close it out.
-- Regards, Tom Ogilvy Ken wrote in message ... Thanks, Tom. It works perfectly! (I did have to add a last "End if" line of code.) -----Original Message----- Dim rng as Range set rng = columns(1).Find("Total") if not rng is nothing then if rng.offset(2,1) rng.offset(0,1) then rng.offset(2,0).Resize(1,2).Interior.ColorIndex = 4 elseif rng.offset(3,1) rng.offset(0,1) then rng.offset(3,0).Resize(1,2).Interior.ColorIndex = 6 else rng.offset(4,0).Resize(1,2).Interior.ColorIndex = 3 End if -- regards, Tom Ogilvy "Ken" wrote in message ... Execl 2000: We have a workbook with a worksheet that can have a varying number of rows. The last 5 rows however will always have data like the following. A B C 51 Total 70 52 53 Test1 20 54 Test2 75 55 Test3 5 We want the macro to compare the number in B53 to B51. If B53 is greated than B51, we want A53 and B53 to be formatted with a green fill color. If B54 is greater than B51, we want A54 and B54 to have a yellow fill. Otherwise we want A55 and B55 to be red. We don't know how to get this to work because the number of rows will always be different when we run the macro. Appreciate any assistance. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I color code comments in cells on Excel spreadsheet? | Excel Worksheet Functions | |||
How to color automatically color code sums in cells | Charts and Charting in Excel | |||
Color code cells | Excel Worksheet Functions | |||
color code cells based on golddigger formula | Excel Discussion (Misc queries) | |||
Code to color selected ws cells | Excel Programming |