Color Pallete

bjurney

Active Member
Joined
Aug 24, 2009
Messages
320
I found this bit of code in my searches and I was wondering if anyone might have an idea of how I can choose a color from the color pallete and have my userform change to the color that I choose? I tried a few things, but it doesnt seem to like to work with a userform. Not even sure if this is possible though.

Code:
Application.Dialogs.Item(xlDialogColorPalette).Show
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,770
Office Version
  1. 2010
Platform
  1. Windows
Try this:

Code:
Sub ColorMyForm()
    myForm.Show vbModeless
    myForm.BackColor = ColorPick(True)
End Sub
 
Function ColorPick(Optional bColor As Boolean = False) As Long
    ' returns the color or colorindex returned from the Patterns dialog
    Dim rSel        As Range
 
    Set rSel = Selection
    Application.ScreenUpdating = False
    With Cells(Rows.Count, "A")
        .Select
        .Interior.ColorIndex = xlColorIndexNone
        Application.Dialogs(xlDialogPatterns).Show
        ColorPick = IIf(bColor, .Interior.Color, .Interior.ColorIndex)
        .Offset(, 1).Copy Destination:=.Cells
    End With
    
    rSel.Select
    ActiveSheet.UsedRange
    Application.ScreenUpdating = True
End Function
 

Watch MrExcel Video

Forum statistics

Threads
1,109,464
Messages
5,528,957
Members
409,848
Latest member
Blomsten
Top