Cell Colour

G

Guest

Dear All,

Can any one tell me how to change the colour of selected cell.

BR
--
*********
IT Manager
DeLaval Ltd.
Cairo-Egypt
*********
|-----------------------------|
|Islam is peace not Terror|
|-----------------------------|
 
R

Rob van Gelder

Manually:
From the Format menu, select Cells
From the Pattern tab, select a colour
Click OK.

Example in VBA:
Sub test()
Range("A1").Interior.Color = vbRed
Range("B1").Interior.Color = RGB(255, 128, 255)
End Sub

You could try recording those manual steps using the macro recorder.
 
G

Guest

Dear Frank,

Well you got my question in a correct way as I need to change the color
of active cell. But I tried to put the statement you sent to me in the VB
Editor and I saved it with one of the sheets of the workbook. But nothing has
worked....
The colors aren't changing at all.
......
 
G

Guest

Dear Frank,

Thanks for the link but I thought that there's something easier instead of
add on.

Best Regards
 
B

Bob Phillips

Ibrahim,

This is what I use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
End With
.FormatConditions(1).Interior.ColorIndex = 20
End With

End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

Paul Black

Patrick Molloy Posted this Code Below.

Quote :-
****************************************************************
Use the Cell's Interior.ColorIndex property

Sub Test
Dim i
For i = 0 To 56
Cells(i + 1, 1) = i
Cells(i + 1, 2).Interior.ColorIndex = i
Next
End Sub

It Shows ALL the Available Colours. Note, Colour '0' is NO Fill.
****************************************************************

Is there ANY way this can be Modified to Also Show the "RGB" Number.

Thanks in Advance.
All the Best
Paul
 
P

Peter T

Is there ANY way this can be Modified to Also Show the "RGB" Number.

If you mean value between 0 (black) to 16777215 (white) simply:

color-value = ActiveWorkbook.Colors(x)

where x is colorindex 1 to 56

It would fail in the loop cited trying to return .Colors(0), but easy to
adapt the loop.

Regards,
Peter
 
T

Tom Ogilvy

so on like this as a possibility:

Sub Test()
Dim i
For i = 0 To 56
Cells(i + 1, 1) = i
Cells(i + 1, 2).Interior.ColorIndex = i
If i <> 0 Then Cells(i + 1, 3).Value = _
ActiveWorkbook.Colors(i)
Next
End Sub

assuming the upperbound remains at 56.
 
G

Gord Dibben

Paul

Sub colors56()
'David McRitchie
'57 colors, 0 to 56

'****************needs ATP loaded*******************

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
Dim str0 As String, str As String
Sheets.Add
For i = 0 To 56
Cells(i + 1, 1).Interior.ColorIndex = i
Cells(i + 1, 1).Value = "[Color " & i & "]"
Cells(i + 1, 2).Font.ColorIndex = i
Cells(i + 1, 2).Value = "[Color " & i & "]"
str0 = Right("000000" & Hex(Cells(i + 1, 1).Interior.Color), 6)
'Excel shows nibbles in reverse order so make it as RGB
str = Right(str0, 2) & Mid(str0, 3, 2) & Left(str0, 2)
'generating 2 columns in the HTML table
Cells(i + 1, 3) = "#" & str & "#" & str & ""
Cells(i + 1, 4).Formula = "=Hex2dec(""" & Right(str0, 2) & """)"
Cells(i + 1, 5).Formula = "=Hex2dec(""" & Mid(str0, 3, 2) & """)"
Cells(i + 1, 6).Formula = "=Hex2dec(""" & Left(str0, 2) & """)"
Cells(i + 1, 7) = "[Color " & i & ")"
Next i
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

For more on Colors from David.......

http://www.mvps.org/dmcritchie/excel/colors.htm

Gord Dibben Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Out of office assistant 1
Domain Configuration 1
Tasks not displayed 1
Field Customization 1
Network icons 1
Can't specify Pages for print out 1
Unattended Installation 1
Mail headers and details 5

Top