Search : in
By :

Vba conditional formatting

Last answer on Mar 3, 2009 2:38:24 am GMT Tina, on Mar 2, 2009 10:41:39 pm GMT 
 Report this message to moderators

Hello,

Configuration: Windows XP
Internet Explorer 6.0

Best answers for « vba conditional formatting » in :
Unlimited Conditional Formatting Show Unlimited Conditional Formatting Introduction Principle Code Introduction The limitation of MFC (Conditional Formatting) to Excel version 2007 is less than 3. This is very short. Having seen many applications to push the limit, I am...
Colouring cells on conditions ShowColouring cells on conditions There are many pratical functions under Excel which is not commonly used. Example: If you wish a cell automatically turns red (or other formatting border, frame etc) under one condition: a result, a...
[VBA] A function that returns the color of an active MFC Show[VBA] A function that returns the color of an active MFC This function returns the value of the active format in conditional formatting. With the function below, two values can be returned. Mode = 0: the value of Interior.ColorIndex...
Adding a VBA CommandButton with its respective the code ShowAdding a VBA CommandButton with its respective the code Paste these two sub in a general module (Module1 for example). Sub CreateButton() Dim Obj As Object Dim Code As String Sheets("Sheet1").Select 'create button ...
Download HP USB Disk Storage Format Tool ShowHP USB Disk Storage Format Tool is a small utility allowing to format a key USB or READER MP4. It also allows to make a key (Bootable). This software works with all keys and readers MP4 of the market. To make work this utility under Windows...
Download Format Factory ShowFormat Factory is an application that allows conversion of various types of media files. It has various characteristics that allow you to customize a lot of stuff like: Convert video formats, audio and picture shows. Repair damaged files. Reduce...
Spreadsheets - Conditional expressions ShowWhat is a Conditional Structure? Conditional structures are instructions that allow to test if a condition is true or not. Conditional structures may be associated together. To successfully execute these tests using logical functions, spreadsheets...
MKV format (Matroska Video) ShowMKV format The MKV format (Matroska Video) is an entirely free video format. More precisely, it is a container (hence the name Matroska, in reference to the Russian dolls contained within another) making it possible to contain video (DivX, Xvid,...
Formatting - Formatting a hard drive ShowBefore trying to understand formatting, you first need to understand how a hard drive works. Many people do not distinguish low-level formatting (also called physical formatting) from high-level formatting (also called logical formatting). Even...

1

Tina, on Mar 2, 2009 10:51:49 pm GMT

Hi,
I've entered in the following code:
The problem I'm facing is that when I do select a cell and change it to any of the following options, it colours momentarily and then as soon as I go to another cell, it reverts back to normal.
How do I ensure that it stays a certain colour as long as the cell has that particular value?
Thanks for your help in advance. You people who answer questions from random strangers are angels!!!
:-) - Tina

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("i6:Ae28")) Is Nothing Then
With Target
Select Case .Value
Case Is = "AOD"
.Font.Bold = True
.Interior.ColorIndex = 36
Case Is = "MISC"
.Font.Bold = True
.Interior.ColorIndex = 40
Case Is = "PH"
.Font.Bold = True
.Interior.ColorIndex = 15
Case Else
.Font.Bold = False
.Interior.ColorIndex = 0
End Select
End With
End If
End Sub

Reply to Tina

2

WutUp WutUp, on Mar 3, 2009 12:06:29 am GMT

I am using Office 2007, but I saved the workbook as 97-2003. I used your code and just randomly entered values in the range based on your criteria, but I did not get the issue you were referring to. Maybe you can try the file I used and see.

[URL=http://www.4shared.com/file/90418748/420881a4/Color_Cel­ls.html]Color Cells.xls/URL

Reply to WutUp WutUp

3

Tina, on Mar 3, 2009 12:20:20 am GMT

I couldn't access ur file due to a firewall at work.

In the sheet, I do have code to highlight the row and column of any selected cell, it's a separate code...would that have anything to do with it?

However,the normal conditional formating (the limited 3 provided by Excel) is working perfectly.

Reply to Tina

4

WutUp WutUp, on Mar 3, 2009 12:28:05 am GMT

Yes, I believe so. If I'm understanding your statement correctly. If you are highlighting a row or column instead of a cell, once a cell is selected outside of the current range then the intersect moves to the new selected range.

Reply to WutUp WutUp

5

Tina, on Mar 3, 2009 12:43:09 am GMT

Ok,this is what I have...just to confirm what ur saying is right...

is the following code preventing the cell to remain the colour specified for that text if i move to another cell?

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)


Static rr
Static cc

If cc <> "" Then
With Columns(cc).Interior
.ColorIndex = xlNone
End With
With Rows(rr).Interior
.ColorIndex = xlNone
End With
End If

r = Selection.Row
c = Selection.Column
rr = r
cc = c

With Columns(c).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With
With Rows(r).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPage = Range("i6:af28")
For Each Cell In MyPage

If Cell.Value = "AOD" Then
Cell.Interior.ColorIndex = 36
End If
If Cell.Value = "MISC" Then
Cell.Interior.ColorIndex = 16
End If
If Cell.Value = "PH" Then
Cell.Interior.ColorIndex = 15
End If

If Cell.Value <> "AOD" And Cell.Value <> "Misc" And Cell.Value <> "PH" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub

Reply to Tina

6

WutUp WutUp, on Mar 3, 2009 12:55:03 am GMT

OK, comment the code at the top and then click somewhere. You are wanting the color to stay?

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Static rr
Static cc

'If cc <> "" Then
'With Columns(cc).Interior
'.ColorIndex = xlNone
'End With
'With Rows(rr).Interior
'.ColorIndex = xlNone
'End With
'End If

r = Selection.Row
c = Selection.Column
rr = r
cc = c

With Columns(c).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With
With Rows(r).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With

End Sub

Reply to WutUp WutUp

7

Tina, on Mar 3, 2009 12:59:38 am GMT

Yes I want the colour to stay just like in the normal way of conditional formatting.

If cell A1 = AOD, then cell should be coloured yellow.

Just because I go to cell A2, A1 shouldn't lose the colour yellow while the cell value is still AOD.

Is there a way to do this while still being able to hightlight row and column of a cell?

Reply to Tina

8

WutUp WutUp, on Mar 3, 2009 1:34:33 am GMT
  • +1

Sorry, I missed the code at the bottom. The click event will override the other Sub. If you combine the two maybe it gets you closer to what you want??? Later...


Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Static rr
Static cc

If cc <> "" Then
With Columns(cc).Interior
.ColorIndex = xlNone
End With
With Rows(rr).Interior
.ColorIndex = xlNone
End With
End If

r = Selection.Row
c = Selection.Column
rr = r
cc = c

Set MyPage = Range("i6:af28")
For Each Cell In MyPage

If Cell.Value = "AOD" Then
Cell.Interior.ColorIndex = 36
'End If
ElseIf Cell.Value = "MISC" Then
Cell.Interior.ColorIndex = 16
'End If
ElseIf Cell.Value = "PH" Then
Cell.Interior.ColorIndex = 15
End If

If Cell.Value <> "AOD" And Cell.Value <> "MISC" And Cell.Value <> "PH" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
With Columns(c).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With
With Rows(r).Interior
.ColorIndex = 20
.Pattern = xlSolid
End With


End Sub

Reply to WutUp WutUp

9

 Tina, on Mar 3, 2009 2:38:24 am GMT

That worked perfectly! and thank you for your prompt response!!!
Thank you so much!!!! ;-)

Reply to Tina