Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default selective sheet formating

On a sheet I have a list of names with information beside it. The name may
repeat several times one after the other in the list and the list could be
anywhere from 1 to 140 rows. So it is easier to read I was wondering whether
it is possible to change the cell shading (for part of the row) based on the
name automatically?

The names would be unknown to the macro:

Name1 <yellow shading
Name1 <yellow shading
Name1 <yellow shading
Name2 <the name changed, so pick another colour, blue
Name3 <the name changed, so pick another colour, green
Name3 <green shading
<blank <leave shading

I am pretty sure I could do all the coding, simply by reading each cell in
turn, checking the format and making changes as required ( or is there a
smarter way?) and run from say a button on the page, BUT can this macro be
started simply because someone changed the name in a cell?

--
Trefor
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 903
Default selective sheet formating

Hi Trefor,
see Conditional Formatting
http://www.mvps.org/dmcritchie/excel...t.htm#grouping

BTW the solution is for two colors which is all you need,
but it will not handle blank rows. If you want to process blank rows
differently the way you actually marked you would need a macro. If you can
use Conditional Formatting it is a lot simpler and faster.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Trefor" wrote in message ...
On a sheet I have a list of names with information beside it. The name may
repeat several times one after the other in the list and the list could be
anywhere from 1 to 140 rows. So it is easier to read I was wondering whether
it is possible to change the cell shading (for part of the row) based on the
name automatically?

The names would be unknown to the macro:

Name1 <yellow shading
Name1 <yellow shading
Name1 <yellow shading
Name2 <the name changed, so pick another colour, blue
Name3 <the name changed, so pick another colour, green
Name3 <green shading
<blank <leave shading

I am pretty sure I could do all the coding, simply by reading each cell in
turn, checking the format and making changes as required ( or is there a
smarter way?) and run from say a button on the page, BUT can this macro be
started simply because someone changed the name in a cell?

--
Trefor




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default selective sheet formating

David,

Many thanks. AND if you don't mind me making a suggestion in return:

=IF($E2="",2,MOD(OFFSET($E2,-1,0)+ OR($A2<OFFSET($A2,-1,0),
$B2<OFFSET($B2,-1,0)),2))

The fix for an empty cell AND the possible use of three colours in the
Conditional Formatting.

Thanks again.


--
Trefor


"David McRitchie" wrote:

Hi Trefor,
see Conditional Formatting
http://www.mvps.org/dmcritchie/excel...t.htm#grouping

BTW the solution is for two colors which is all you need,
but it will not handle blank rows. If you want to process blank rows
differently the way you actually marked you would need a macro. If you can
use Conditional Formatting it is a lot simpler and faster.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Trefor" wrote in message ...
On a sheet I have a list of names with information beside it. The name may
repeat several times one after the other in the list and the list could be
anywhere from 1 to 140 rows. So it is easier to read I was wondering whether
it is possible to change the cell shading (for part of the row) based on the
name automatically?

The names would be unknown to the macro:

Name1 <yellow shading
Name1 <yellow shading
Name1 <yellow shading
Name2 <the name changed, so pick another colour, blue
Name3 <the name changed, so pick another colour, green
Name3 <green shading
<blank <leave shading

I am pretty sure I could do all the coding, simply by reading each cell in
turn, checking the format and making changes as required ( or is there a
smarter way?) and run from say a button on the page, BUT can this macro be
started simply because someone changed the name in a cell?

--
Trefor





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 903
Default selective sheet formating

Hi Trefor,
If this applies to the example on my web page,
http://www.mvps.org/dmcritchie/excel...t.htm#grouping
then your formula would be put into E2 (anywhere but column A or B
and would be written as (the $E2 is changed to $A2 as below AND avoid a circular reference)
E2: =IF($A2="",2,MOD(OFFSET($E2,-1,0)+ OR($A2<OFFSET($A2,-1,0),
$B2<OFFSET($B2,-1,0)),2))

The color after the blank row(s) will always be the color you assign to 1
So the color after may match the color before the blank line
or if may not match. If you left the formula alone you would
have a consistent color banding with the blank row treated
as a normal change. The Effect to me with your change is that by
adding a 3rd coloring or a blank row is that it is breaking apart equals when
the colors above and below match.

So I would suggest:
E2:
= IF($A2="",IF($A1="",$E1,$E1+2),MOD(OFFSET($E2,-1,0)
+ OR($A2<OFFSET($A2,-1,0), $B2<OFFSET($B2,-1,0)),2))

C.F. $E1=1 yellow
C.F. $E11 turquiose (value 2 or 3)
anything else is default without color

with the caveat that an empty cell in column A will alway cause an unequal
break if the row above and below are equal to each other but not empty.

My web page has been modified to incorporate your suggestion, but
without showing use of a blank row (col A) in the example..
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Trefor" wrote in message ...
Many thanks. AND if you don't mind me making a suggestion in return:

=IF($E2="",2,MOD(OFFSET($E2,-1,0)+ OR($A2<OFFSET($A2,-1,0),
$B2<OFFSET($B2,-1,0)),2))

The fix for an empty cell AND the possible use of three colours in the
Conditional Formatting.



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
FORMATING ONE SHEET TO MOVE U TO ANOTHER A. Gray Excel Worksheet Functions 0 May 29th 08 03:59 PM
Repeating formating from one sheet to another MrReeLady Excel Discussion (Misc queries) 2 February 1st 08 02:10 PM
Selective rows from one sheet to another [email protected] Excel Discussion (Misc queries) 8 December 6th 07 08:19 PM
Sheet Group & Formating in VBA Phatchef24[_3_] Excel Programming 1 August 23rd 04 07:51 PM
formating sheet Node321 Excel Programming 2 September 19th 03 12:56 PM


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