I am using Excel VBA to create and organize color palettes and gradients using Cell interior color and multiple colorspaces. I am successful in getting the formula and code to get the numeric RGB values of selected cells, but when I try to put those values in a custom Userform, it does not populate for some reason.
Userform in question. The R, G and B textboxes should be populated by 191, 143, 0
Here is the sub before it runs the userform. It is set up so it will either run a different userform or messagebox depending on how I do my cell selection for gradients.
Sub RunColorMixer()
Dim CellCount As Integer, RowCount As Integer, ColCount As Integer
Dim ActiveRow As Integer, ActiveCol As Integer
Dim SelectRow As Integer, SelectCol As Integer
Dim Orientation As String
'Input Phase
CellCount = Application.Selection.Cells.Count
RowCount = Application.Selection.Rows.Count
ColCount = Application.Selection.Columns.Count
ActiveRow = ActiveCell.Row
ActiveCol = ActiveCell.Column
SelectRow = Application.Selection.Row
SelectCol = Application.Selection.Column
Range("D1").Value = CellCount
Range("E1").Value = RowCount
Range("F1").Value = ColCount
Range("G1").Value = ActiveRow
Range("H1").Value = ActiveCol
Range("I1").Value = SelectRow
Range("J1").Value = SelectCol
Range("K1").Value = Orientation
'Determine Orientation
If CellCount = 1 Then 'Case 1 Single Cell
ColorpickerSingle.Show
ElseIf RowCount > 1 And ColCount > 1 Then 'Case 2 Diagonal
MsgBox "Diagonals not supported! Please keep gradients on 1 row or column only!"
Else
ColorpickerGradient.Show
End If
End Sub
Here is the initialize code
Private Sub ColorpickerGradient_Initialize()
Dim CellCount As Integer, RowCount As Integer, ColCount As Integer
Dim ActiveRow As Integer, ActiveCol As Integer
Dim SelectRow As Integer, SelectCol As Integer
Dim Orient As String
Dim ColorValue1 As Variant, ColorValue2 As Variant
'Input Phase
CellCount = Application.Selection.Cells.Count
RowCount = Application.Selection.Rows.Count
ColCount = Application.Selection.Columns.Count
ActiveRow = ActiveCell.Row
ActiveCol = ActiveCell.Column
SelectRow = Application.Selection.Row
SelectCol = Application.Selection.Column
'Determine Orientation
If ActiveRow = SelectRow And ActiveCol = SelectCol Then 'Either Down or Right
If RowCount > 1 Then 'Case 3 Down
Orient = "Down"
Else 'Case 4 Right
Orient = "Right"
Orientation.Text = "Right"
End If
Else 'Either Up or Left
If RowCount > 1 Then 'Case 5 Up
Orient = "Up"
Orientation.Text = "Up"
Else 'Case 6 Left
Orient = "Left"
Orientation.Text = "Left"
End If
End If
'Input Color
ColorValue1 = ActiveCell.Interior.Color
Select Case Orientation
Case "Up"
ColorValue2 = ActiveCell.Offset(-(CellCount - 1), 0).Interior.Color
Case "Left"
ColorValue2 = ActiveCell.Offset(0, -(CellCount - 1)).Interior.Color
Case "Down"
ColorValue2 = ActiveCell.Offset((CellCount - 1), 0).Interior.Color
Case "Right"
ColorValue2 = ActiveCell.Offset(0, (CellCount - 1)).Interior.Color
End Select
sR1.Value = ColorValue1 Mod 256
sG1.Value = (ColorValue1 \ 256) Mod 256
sB1.Value = ColorValue1 \ 65536
sR2.Value = ColorValue2 Mod 256
sG2.Value = (ColorValue2 \ 256) Mod 256
sB2.Value = ColorValue2 \ 65536
End Sub
I also made sure that I have named my textboxes correctly. It should have at least the R channel textbox filled
The Initialize
event handler method doesn't use the name of the form, so it should be
Private Sub UserForm_Initialize()
and not
Private Sub ColorpickerGradient_Initialize()