PC Review


Reply
Thread Tools Rate Thread

Conditional formatting in macro

 
 
Zak
Guest
Posts: n/a
 
      19th Feb 2008
Hi,

I have the following conditional formatting requirements to be put in one
macro -

1) If no info is entered in a cell or cell in blank then colour grey (in all
sheet)
2) If cell value is less than cell C6 in column C then colour Red
3) If cell value is more than cell C6 in column C then colour Yellow
3) Current month column to be highlighted

are you able to help? thanks a lot.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      19th Feb 2008
Zak,

You need to define this a bit more because to check every cell in a
worksheet (>16million) and set the background according to the contents is
going to take a very long time.

Mike

"Zak" wrote:

> Hi,
>
> I have the following conditional formatting requirements to be put in one
> macro -
>
> 1) If no info is entered in a cell or cell in blank then colour grey (in all
> sheet)
> 2) If cell value is less than cell C6 in column C then colour Red
> 3) If cell value is more than cell C6 in column C then colour Yellow
> 3) Current month column to be highlighted
>
> are you able to help? thanks a lot.

 
Reply With Quote
 
Zak
Guest
Posts: n/a
 
      19th Feb 2008
Hi,

Its not a big spreadsheet atol..would this make it easier now?

Just want to say if something is blank then turn grey.. the whole sheet
would probably only have like 40blanks.

The current month column - there is only one of these in the whole sheet.

And what if i had names instead of cell refs? for example, if "AB" less than
"CD" in row 3 then colour red etc..?

I thought it would be easily done, like with conditional formatting... maybe
not!

So, can this not be done?

thanks.

"Mike H" wrote:

> Zak,
>
> You need to define this a bit more because to check every cell in a
> worksheet (>16million) and set the background according to the contents is
> going to take a very long time.
>
> Mike
>
> "Zak" wrote:
>
> > Hi,
> >
> > I have the following conditional formatting requirements to be put in one
> > macro -
> >
> > 1) If no info is entered in a cell or cell in blank then colour grey (in all
> > sheet)
> > 2) If cell value is less than cell C6 in column C then colour Red
> > 3) If cell value is more than cell C6 in column C then colour Yellow
> > 3) Current month column to be highlighted
> >
> > are you able to help? thanks a lot.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Feb 2008
Zak,

I've assumed your range is A1 - B100 , try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
Set myrange = Range("A1:B100")
For Each c In myrange
If IsEmpty(c) Then
c.Interior.ColorIndex = 15
End If
Next
End If
End Sub

Mike

"Zak" wrote:

> Hi,
>
> Its not a big spreadsheet atol..would this make it easier now?
>
> Just want to say if something is blank then turn grey.. the whole sheet
> would probably only have like 40blanks.
>
> The current month column - there is only one of these in the whole sheet.
>
> And what if i had names instead of cell refs? for example, if "AB" less than
> "CD" in row 3 then colour red etc..?
>
> I thought it would be easily done, like with conditional formatting... maybe
> not!
>
> So, can this not be done?
>
> thanks.
>
> "Mike H" wrote:
>
> > Zak,
> >
> > You need to define this a bit more because to check every cell in a
> > worksheet (>16million) and set the background according to the contents is
> > going to take a very long time.
> >
> > Mike
> >
> > "Zak" wrote:
> >
> > > Hi,
> > >
> > > I have the following conditional formatting requirements to be put in one
> > > macro -
> > >
> > > 1) If no info is entered in a cell or cell in blank then colour grey (in all
> > > sheet)
> > > 2) If cell value is less than cell C6 in column C then colour Red
> > > 3) If cell value is more than cell C6 in column C then colour Yellow
> > > 3) Current month column to be highlighted
> > >
> > > are you able to help? thanks a lot.

 
Reply With Quote
 
Zak
Guest
Posts: n/a
 
      19th Feb 2008
Hi,

I inserted this code into a module but when i go to find it to play it i
cant seem to find it, its no where to be seen! is there something in the code
that would make it do that or am i doing something wrong? i have tried
another macro and that works fine..

i put it in exactly like you said. Also, am i able to get another condition
put in? If cell contains curent month then put a green border around whole
column? and in the code i said if is something is >,< than C6 but in future
this cell is likely to move. am i able to say a word (whatever is in the
cell) instead of C6?

thanks a lot.




"Mike H" wrote:

> Zak,
>
> I've assumed your range is A1 - B100 , try this
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Target.Cells.Count > 1 Then Exit Sub
> If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
> If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
> If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
> Set myrange = Range("A1:B100")
> For Each c In myrange
> If IsEmpty(c) Then
> c.Interior.ColorIndex = 15
> End If
> Next
> End If
> End Sub
>
> Mike
>
> "Zak" wrote:
>
> > Hi,
> >
> > Its not a big spreadsheet atol..would this make it easier now?
> >
> > Just want to say if something is blank then turn grey.. the whole sheet
> > would probably only have like 40blanks.
> >
> > The current month column - there is only one of these in the whole sheet.
> >
> > And what if i had names instead of cell refs? for example, if "AB" less than
> > "CD" in row 3 then colour red etc..?
> >
> > I thought it would be easily done, like with conditional formatting... maybe
> > not!
> >
> > So, can this not be done?
> >
> > thanks.
> >
> > "Mike H" wrote:
> >
> > > Zak,
> > >
> > > You need to define this a bit more because to check every cell in a
> > > worksheet (>16million) and set the background according to the contents is
> > > going to take a very long time.
> > >
> > > Mike
> > >
> > > "Zak" wrote:
> > >
> > > > Hi,
> > > >
> > > > I have the following conditional formatting requirements to be put in one
> > > > macro -
> > > >
> > > > 1) If no info is entered in a cell or cell in blank then colour grey (in all
> > > > sheet)
> > > > 2) If cell value is less than cell C6 in column C then colour Red
> > > > 3) If cell value is more than cell C6 in column C then colour Yellow
> > > > 3) Current month column to be highlighted
> > > >
> > > > are you able to help? thanks a lot.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Feb 2008
Its worksheet code so right click the sheet tab, view code and paste it in
there

"Zak" wrote:

> Hi,
>
> I inserted this code into a module but when i go to find it to play it i
> cant seem to find it, its no where to be seen! is there something in the code
> that would make it do that or am i doing something wrong? i have tried
> another macro and that works fine..
>
> i put it in exactly like you said. Also, am i able to get another condition
> put in? If cell contains curent month then put a green border around whole
> column? and in the code i said if is something is >,< than C6 but in future
> this cell is likely to move. am i able to say a word (whatever is in the
> cell) instead of C6?
>
> thanks a lot.
>
>
>
>
> "Mike H" wrote:
>
> > Zak,
> >
> > I've assumed your range is A1 - B100 , try this
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > If Target.Cells.Count > 1 Then Exit Sub
> > If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
> > If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
> > If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
> > Set myrange = Range("A1:B100")
> > For Each c In myrange
> > If IsEmpty(c) Then
> > c.Interior.ColorIndex = 15
> > End If
> > Next
> > End If
> > End Sub
> >
> > Mike
> >
> > "Zak" wrote:
> >
> > > Hi,
> > >
> > > Its not a big spreadsheet atol..would this make it easier now?
> > >
> > > Just want to say if something is blank then turn grey.. the whole sheet
> > > would probably only have like 40blanks.
> > >
> > > The current month column - there is only one of these in the whole sheet.
> > >
> > > And what if i had names instead of cell refs? for example, if "AB" less than
> > > "CD" in row 3 then colour red etc..?
> > >
> > > I thought it would be easily done, like with conditional formatting... maybe
> > > not!
> > >
> > > So, can this not be done?
> > >
> > > thanks.
> > >
> > > "Mike H" wrote:
> > >
> > > > Zak,
> > > >
> > > > You need to define this a bit more because to check every cell in a
> > > > worksheet (>16million) and set the background according to the contents is
> > > > going to take a very long time.
> > > >
> > > > Mike
> > > >
> > > > "Zak" wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I have the following conditional formatting requirements to be put in one
> > > > > macro -
> > > > >
> > > > > 1) If no info is entered in a cell or cell in blank then colour grey (in all
> > > > > sheet)
> > > > > 2) If cell value is less than cell C6 in column C then colour Red
> > > > > 3) If cell value is more than cell C6 in column C then colour Yellow
> > > > > 3) Current month column to be highlighted
> > > > >
> > > > > are you able to help? thanks a lot.

 
Reply With Quote
 
Zak
Guest
Posts: n/a
 
      19th Feb 2008
I did this but how do i play it then? when i go back to worksheet view i
click on macros and play and i cant see it there, is there a different way to
play worksheet macros. sorry i dont know!

"Mike H" wrote:

> Its worksheet code so right click the sheet tab, view code and paste it in
> there
>
> "Zak" wrote:
>
> > Hi,
> >
> > I inserted this code into a module but when i go to find it to play it i
> > cant seem to find it, its no where to be seen! is there something in the code
> > that would make it do that or am i doing something wrong? i have tried
> > another macro and that works fine..
> >
> > i put it in exactly like you said. Also, am i able to get another condition
> > put in? If cell contains curent month then put a green border around whole
> > column? and in the code i said if is something is >,< than C6 but in future
> > this cell is likely to move. am i able to say a word (whatever is in the
> > cell) instead of C6?
> >
> > thanks a lot.
> >
> >
> >
> >
> > "Mike H" wrote:
> >
> > > Zak,
> > >
> > > I've assumed your range is A1 - B100 , try this
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > If Target.Cells.Count > 1 Then Exit Sub
> > > If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
> > > If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
> > > If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
> > > Set myrange = Range("A1:B100")
> > > For Each c In myrange
> > > If IsEmpty(c) Then
> > > c.Interior.ColorIndex = 15
> > > End If
> > > Next
> > > End If
> > > End Sub
> > >
> > > Mike
> > >
> > > "Zak" wrote:
> > >
> > > > Hi,
> > > >
> > > > Its not a big spreadsheet atol..would this make it easier now?
> > > >
> > > > Just want to say if something is blank then turn grey.. the whole sheet
> > > > would probably only have like 40blanks.
> > > >
> > > > The current month column - there is only one of these in the whole sheet.
> > > >
> > > > And what if i had names instead of cell refs? for example, if "AB" less than
> > > > "CD" in row 3 then colour red etc..?
> > > >
> > > > I thought it would be easily done, like with conditional formatting... maybe
> > > > not!
> > > >
> > > > So, can this not be done?
> > > >
> > > > thanks.
> > > >
> > > > "Mike H" wrote:
> > > >
> > > > > Zak,
> > > > >
> > > > > You need to define this a bit more because to check every cell in a
> > > > > worksheet (>16million) and set the background according to the contents is
> > > > > going to take a very long time.
> > > > >
> > > > > Mike
> > > > >
> > > > > "Zak" wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have the following conditional formatting requirements to be put in one
> > > > > > macro -
> > > > > >
> > > > > > 1) If no info is entered in a cell or cell in blank then colour grey (in all
> > > > > > sheet)
> > > > > > 2) If cell value is less than cell C6 in column C then colour Red
> > > > > > 3) If cell value is more than cell C6 in column C then colour Yellow
> > > > > > 3) Current month column to be highlighted
> > > > > >
> > > > > > are you able to help? thanks a lot.

 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      19th Feb 2008
The code is triggered by a worksheet change event - you do not need to run
it manually.

Each 'change' on the specific worksheet causes the code to run and setup the
color coding you require within the range specified


--

Regards,
Nigel
(E-Mail Removed)



"Zak" <(E-Mail Removed)> wrote in message
news:944784FA-F13C-4841-8589-(E-Mail Removed)...
>I did this but how do i play it then? when i go back to worksheet view i
> click on macros and play and i cant see it there, is there a different way
> to
> play worksheet macros. sorry i dont know!
>
> "Mike H" wrote:
>
>> Its worksheet code so right click the sheet tab, view code and paste it
>> in
>> there
>>
>> "Zak" wrote:
>>
>> > Hi,
>> >
>> > I inserted this code into a module but when i go to find it to play it
>> > i
>> > cant seem to find it, its no where to be seen! is there something in
>> > the code
>> > that would make it do that or am i doing something wrong? i have tried
>> > another macro and that works fine..
>> >
>> > i put it in exactly like you said. Also, am i able to get another
>> > condition
>> > put in? If cell contains curent month then put a green border around
>> > whole
>> > column? and in the code i said if is something is >,< than C6 but in
>> > future
>> > this cell is likely to move. am i able to say a word (whatever is in
>> > the
>> > cell) instead of C6?
>> >
>> > thanks a lot.
>> >
>> >
>> >
>> >
>> > "Mike H" wrote:
>> >
>> > > Zak,
>> > >
>> > > I've assumed your range is A1 - B100 , try this
>> > >
>> > > Private Sub Worksheet_Change(ByVal Target As Range)
>> > > If Target.Cells.Count > 1 Then Exit Sub
>> > > If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
>> > > If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
>> > > If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
>> > > Set myrange = Range("A1:B100")
>> > > For Each c In myrange
>> > > If IsEmpty(c) Then
>> > > c.Interior.ColorIndex = 15
>> > > End If
>> > > Next
>> > > End If
>> > > End Sub
>> > >
>> > > Mike
>> > >
>> > > "Zak" wrote:
>> > >
>> > > > Hi,
>> > > >
>> > > > Its not a big spreadsheet atol..would this make it easier now?
>> > > >
>> > > > Just want to say if something is blank then turn grey.. the whole
>> > > > sheet
>> > > > would probably only have like 40blanks.
>> > > >
>> > > > The current month column - there is only one of these in the whole
>> > > > sheet.
>> > > >
>> > > > And what if i had names instead of cell refs? for example, if "AB"
>> > > > less than
>> > > > "CD" in row 3 then colour red etc..?
>> > > >
>> > > > I thought it would be easily done, like with conditional
>> > > > formatting... maybe
>> > > > not!
>> > > >
>> > > > So, can this not be done?
>> > > >
>> > > > thanks.
>> > > >
>> > > > "Mike H" wrote:
>> > > >
>> > > > > Zak,
>> > > > >
>> > > > > You need to define this a bit more because to check every cell in
>> > > > > a
>> > > > > worksheet (>16million) and set the background according to the
>> > > > > contents is
>> > > > > going to take a very long time.
>> > > > >
>> > > > > Mike
>> > > > >
>> > > > > "Zak" wrote:
>> > > > >
>> > > > > > Hi,
>> > > > > >
>> > > > > > I have the following conditional formatting requirements to be
>> > > > > > put in one
>> > > > > > macro -
>> > > > > >
>> > > > > > 1) If no info is entered in a cell or cell in blank then colour
>> > > > > > grey (in all
>> > > > > > sheet)
>> > > > > > 2) If cell value is less than cell C6 in column C then colour
>> > > > > > Red
>> > > > > > 3) If cell value is more than cell C6 in column C then colour
>> > > > > > Yellow
>> > > > > > 3) Current month column to be highlighted
>> > > > > >
>> > > > > > are you able to help? thanks a lot.


 
Reply With Quote
 
Zak
Guest
Posts: n/a
 
      19th Feb 2008
Hi.

I am now trying to trigger some change but it doesnt seem to do anyting.
most the sheet in the specified range is blank so it should be grey but it
isnt! i am deliberately trying or evoke the conditions but again nothing
happens.

Does this have to be a worksheet function because the spreadsheet this is to
be used on would be created from another report via a macro and it will
change weekly. This would mean the code will no longer stay as it is
something that is re-created. I do not want to insert this code each time,
can i not make it a part of the normal macro?

Also, can i use words instead of cell refs? as cell refs are likely to
change over time.

I also wanted to know how i can insert a condition to make current month
column blue bordered.

thanks.

"Nigel" wrote:

> The code is triggered by a worksheet change event - you do not need to run
> it manually.
>
> Each 'change' on the specific worksheet causes the code to run and setup the
> color coding you require within the range specified
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "Zak" <(E-Mail Removed)> wrote in message
> news:944784FA-F13C-4841-8589-(E-Mail Removed)...
> >I did this but how do i play it then? when i go back to worksheet view i
> > click on macros and play and i cant see it there, is there a different way
> > to
> > play worksheet macros. sorry i dont know!
> >
> > "Mike H" wrote:
> >
> >> Its worksheet code so right click the sheet tab, view code and paste it
> >> in
> >> there
> >>
> >> "Zak" wrote:
> >>
> >> > Hi,
> >> >
> >> > I inserted this code into a module but when i go to find it to play it
> >> > i
> >> > cant seem to find it, its no where to be seen! is there something in
> >> > the code
> >> > that would make it do that or am i doing something wrong? i have tried
> >> > another macro and that works fine..
> >> >
> >> > i put it in exactly like you said. Also, am i able to get another
> >> > condition
> >> > put in? If cell contains curent month then put a green border around
> >> > whole
> >> > column? and in the code i said if is something is >,< than C6 but in
> >> > future
> >> > this cell is likely to move. am i able to say a word (whatever is in
> >> > the
> >> > cell) instead of C6?
> >> >
> >> > thanks a lot.
> >> >
> >> >
> >> >
> >> >
> >> > "Mike H" wrote:
> >> >
> >> > > Zak,
> >> > >
> >> > > I've assumed your range is A1 - B100 , try this
> >> > >
> >> > > Private Sub Worksheet_Change(ByVal Target As Range)
> >> > > If Target.Cells.Count > 1 Then Exit Sub
> >> > > If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
> >> > > If Target.Value > Range("C6") Then Target.Interior.ColorIndex = 6
> >> > > If Target.Value < Range("C6") Then Target.Interior.ColorIndex = 3
> >> > > Set myrange = Range("A1:B100")
> >> > > For Each c In myrange
> >> > > If IsEmpty(c) Then
> >> > > c.Interior.ColorIndex = 15
> >> > > End If
> >> > > Next
> >> > > End If
> >> > > End Sub
> >> > >
> >> > > Mike
> >> > >
> >> > > "Zak" wrote:
> >> > >
> >> > > > Hi,
> >> > > >
> >> > > > Its not a big spreadsheet atol..would this make it easier now?
> >> > > >
> >> > > > Just want to say if something is blank then turn grey.. the whole
> >> > > > sheet
> >> > > > would probably only have like 40blanks.
> >> > > >
> >> > > > The current month column - there is only one of these in the whole
> >> > > > sheet.
> >> > > >
> >> > > > And what if i had names instead of cell refs? for example, if "AB"
> >> > > > less than
> >> > > > "CD" in row 3 then colour red etc..?
> >> > > >
> >> > > > I thought it would be easily done, like with conditional
> >> > > > formatting... maybe
> >> > > > not!
> >> > > >
> >> > > > So, can this not be done?
> >> > > >
> >> > > > thanks.
> >> > > >
> >> > > > "Mike H" wrote:
> >> > > >
> >> > > > > Zak,
> >> > > > >
> >> > > > > You need to define this a bit more because to check every cell in
> >> > > > > a
> >> > > > > worksheet (>16million) and set the background according to the
> >> > > > > contents is
> >> > > > > going to take a very long time.
> >> > > > >
> >> > > > > Mike
> >> > > > >
> >> > > > > "Zak" wrote:
> >> > > > >
> >> > > > > > Hi,
> >> > > > > >
> >> > > > > > I have the following conditional formatting requirements to be
> >> > > > > > put in one
> >> > > > > > macro -
> >> > > > > >
> >> > > > > > 1) If no info is entered in a cell or cell in blank then colour
> >> > > > > > grey (in all
> >> > > > > > sheet)
> >> > > > > > 2) If cell value is less than cell C6 in column C then colour
> >> > > > > > Red
> >> > > > > > 3) If cell value is more than cell C6 in column C then colour
> >> > > > > > Yellow
> >> > > > > > 3) Current month column to be highlighted
> >> > > > > >
> >> > > > > > are you able to help? thanks a lot.

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting Macro? =?Utf-8?B?bXlkb2dwZWFudXQ=?= Microsoft Excel Programming 3 19th Oct 2007 06:23 PM
Macro Conditional Formatting Sandy Microsoft Excel Worksheet Functions 2 10th May 2007 02:25 PM
Conditional formatting macro K1KKKA Microsoft Excel Discussion 1 27th Apr 2007 02:57 PM
Conditional Formatting in Macro shantanu oak Microsoft Excel Misc 2 14th Jul 2006 01:11 PM
Conditional Formatting or Macro? Brian Microsoft Excel Misc 3 16th Jul 2003 11:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:39 AM.