Option Explicit
Public Sub RGB2Hex()
On Error GoTo MyHandler:
Dim i As Integer
Dim Output As String
Dim YN As Byte
YN = MsgBox("This will take up two full rows on your worksheet." & vbCrLf & _
"Do you want to continue?", vbYesNo, "RGB & HEX")
If Not YN = 6 Then Exit Sub
On Error GoTo NotANumber:
Dim whereStart As Long
whereStart = InputBox("In which row would you like the series to start?", "RGB & HEX")
If whereStart < 1 Or whereStart > 65535 Then GoTo NotANumber:
On Error GoTo MyHandler:
Application.ErrorCheckingOptions.NumberAsText = False
For i = 0 To 255
With Cells(whereStart, i + 1)
.Value = i
.HorizontalAlignment = xlCenter
End With
Output = Hex(i)
If Len(Output) = 1 Then Output = "0" & Output
With Cells(whereStart + 1, i + 1)
.NumberFormat = "@"
.Value = Output
.HorizontalAlignment = xlCenter
End With
Next
Exit Sub
NotANumber:
Err.Clear
MsgBox "You must enter a number between 1 and 65,535", vbOKOnly, "Enter a number"
Exit Sub
MyHandler:
MsgBox Err.Description
Err.Clear
End Sub
|