Your last statement, ActiveSheet.Range("A1").Value = rgb1 will simply write the content of rgb1 into the cell - that is for example the string rgbALPINE. There is no way to force the VBA compiler to interpret the content of rgb1 as a variable name and look into that variable.
As you have a simple list product name - color, you could use a VBA collection - a collection is basically a list of pairs. Every pair has a name (that is the key) and a value - the value can be anything (Variant). When you know the name (the key), you can easily get the value. You know collections from many things in VBA, eg the Workbooks or the Worksheets list.
The following function returns the RGB-Value for a product. It uses a static variable for the collection. static means that the variable "survives" the end of the routine so that the collection must be initialized only once. Note that RGB-Values are internally stored as Long, this is the reason the function returns a Long.
Function getColor(prod As String) As Long
Static colorList As Collection
If colorList Is Nothing Then
' Build the collection if it doesn't exist
Set colorList = New Collection
colorList.Add RGB(177, 160, 199), "ULP"
colorList.Add RGB(255, 192, 0), "PULP"
colorList.Add RGB(0, 112, 192), "SPULP"
colorList.Add RGB(196, 189, 151), "XLSD"
colorList.Add RGB(196, 215, 155), "ALPINE"
colorList.Add RGB(255, 255, 255), "JET"
colorList.Add RGB(255, 0, 0), "SLOPS"
End If
On Error Resume Next ' Prevent runtime error if prod is not part of list
getColor = colorList(prod)
On Error GoTo 0
End Function
Your current AddEvent2-routine is very short. However, I wonder if you really want to write the color number into the cell. I assume that you want to use the color as cell color.
Sub AddEvent2()
Dim p As String, color as Long
p = Sheets("AdminSheet").Cells(4, 23).Value 'Product
color = getColor(p)
If color <> 0 Then
ActiveSheet.Range("A1").Value = color ' This writes the color number into the cell
ActiveSheet.Range("A1").Interior.Color = color ' This set the cell color
ActiveSheet.Shapes(1).Fill.ForeColor.RGB = color ' This sets the color of a Shape
End If
End Sub
rgbas the name of something. Ifpis equal to sayULPand you want to get the value of thergbULPvariable in A1, your approach is not going to work. You need a dictionary or collection or similar that can store name/value pairs.