|
|
|
|
|
|
Excel
|
Translate RGB codes to HEX #rrggbb
|
|
Ease of Use
|
Easy
|
Version tested with
|
2003
|
Submitted by:
|
wnazzaro
|
Description:
|
Add this code to the change event of a worksheet and it will enter the equivalent HEX code of the number entered in the cell to the right of the entered number. If a number outside the range of 0-255 or text is entered, nothing will change on the sheet.
|
Discussion:
|
The company I work for has specified colors to use with any media. While setting up an intranet site, I realized I needed the HEX codes for background colors from the RGB codes the company provided. Searching the internet did not provide me with a thorough understanding of the translation of RGB codes to HEX codes. With this utility, you won't need to find the translation, this will provide it for you. While the Windows calculator will also do this conversion, the calculator can only give one answer at a time. You can enter several numbers into the spreadsheet and find the translation. My co-worker who had done the translation of company colors misread his handwriting and used 70 for 7D, 05 for D5 and F8 instead of FB. With this utility, you won't be forced to do one translation at a time.
|
Code:
|
instructions for use
|
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo MyHandler:
If Target.Count = 1 Then
If IsNumeric(Target) And Target <= 255 And Target >= 0 Then
Application.EnableEvents = False
With Target.Offset(, 1)
.NumberFormat = "@"
.HorizontalAlignment = xlRight
.Value = Hex(Target)
End With
If Len(Target.Offset(, 1)) = 1 Then
Target.Offset(, 1) = "0" & Hex(Target)
End If
Application.EnableEvents = True
End If
End If
Exit Sub
MyHandler:
Err.Clear
Application.EnableEvents = True
End Sub
|
How to use:
|
- Open Excel
- Go to Tools - Macro - Visual Basic Editor
- Click Visual Basic Editor
- Under the folder Microsoft Excel Objects, double click Sheet1 (Sheet1)
- Paste the code in the sheet that opens
- Close the Visual Basic screen
|
Test the code:
|
- Enter a number between 0-255 anywhere on Sheet1 and hit Enter. If you enter 0, 00 is the HEX code for 0 and will appear.
- Enter 255 and hit Enter, FF will appear because FF is the HEX code for 255.
- Enter 204 and hit Enter and CC will be the result.
|
Sample File:
|
HEX codes.zip 9.02KB
|
Approved by mdmackillop
|
This entry has been viewed 136 times.
|
|