+ Reply to Thread
Results 1 to 16 of 16

Sub to list colorindexes and the corresponding fill colours

  1. #1
    Max
    Guest

    Sub to list colorindexes and the corresponding fill colours

    Hi guys,

    (Apologies for the earlier post w/o any subject line)

    I'm looking for a sub which can list all the colorindexes down say col A,
    and all the corresponding fill colors in col B ?

    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----



  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Private Sub CommandButton1_Click()
    Set rng = Range("A1")
    For i = 0 To 50
    rng.Offset(i, 0) = i
    rng.Offset(i, 1).Interior.ColorIndex = i
    Next i
    End Sub


    Mangesh

  3. #3
    Bob Phillips
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Hi Max,

    By fill colour, do you mean the RGB equivalent?

    Public Sub Colours()
    Dim i As Long
    Dim tmp, tRed, tBlue, tGreen

    For i = 1 To 56
    Cells(i, "A").Value = i
    Cells(i, "C").Interior.ColorIndex = i
    tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    Cells(i, "B").Value = "RGB(" & tRed & ", " & tGreen & ", " & tBlue &
    ")"
    Next i
    Columns("B:B").AutoFit

    End Sub

    --
    HTH

    Bob Phillips

    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > Hi guys,
    >
    > (Apologies for the earlier post w/o any subject line)
    >
    > I'm looking for a sub which can list all the colorindexes down say col A,
    > and all the corresponding fill colors in col B ?
    >
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    >
    >




  4. #4
    K Dales
    Guest

    RE: Sub to list colorindexes and the corresponding fill colours

    Not sure exactly what you want, but this sub will give the colorindex in
    column A, the corresponding color value (numeric, the RGB value) in column B,
    and will fill the cell in column C with the specified color:

    Public Sub ShowFillColors()

    For i = 1 To 56
    Sheets("Sheet1").Range("A" & i).Value = i
    Sheets("Sheet1").Range("C" & i).Interior.ColorIndex = i
    Sheets("Sheet1").Range("B" & i).Value = Sheets("Sheet1").Range("C" &
    i).Interior.Color
    Next i

    End Sub


    "Max" wrote:

    > Hi guys,
    >
    > (Apologies for the earlier post w/o any subject line)
    >
    > I'm looking for a sub which can list all the colorindexes down say col A,
    > and all the corresponding fill colors in col B ?
    >
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    >
    >
    >


  5. #5
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Thanks, Mangesh

    Despite several tries at running your sub, I kept hitting a run-time error
    1004
    "Unable to set the colorindex property of the interior class"

    Clicking debug highlighted this line:
    rng.Offset(i, 1).Interior.ColorIndex = i

    What can I do ?
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----
    "mangesh_yadav" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Private Sub CommandButton1_Click()
    > Set rng = Range("A1")
    > For i = 0 To 50
    > rng.Offset(i, 0) = i
    > rng.Offset(i, 1).Interior.ColorIndex = i
    > Next i
    > End Sub




  6. #6
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Thanks, Bob

    Despite several tries at running your sub, I kept hitting:
    Compile error: Sub or Function not defined

    and "GetRGB" was highlighted in the line:
    tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)

    What can I do ?

    > By fill colour, do you mean the RGB equivalent?

    Actually, I'm afraid I don't know <g>. Am new at this.

    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----
    "Bob Phillips" <[email protected]> wrote in message
    news:#[email protected]...
    > Hi Max,
    >


    >
    > Public Sub Colours()
    > Dim i As Long
    > Dim tmp, tRed, tBlue, tGreen
    >
    > For i = 1 To 56
    > Cells(i, "A").Value = i
    > Cells(i, "C").Interior.ColorIndex = i
    > tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    > Cells(i, "B").Value = "RGB(" & tRed & ", " & tGreen & ", " & tBlue

    &
    > ")"
    > Next i
    > Columns("B:B").AutoFit
    >
    > End Sub




  7. #7
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Thanks, K Dales !
    Marvellous, spot on !
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----
    "K Dales" <[email protected]> wrote in message
    news:[email protected]...
    > Not sure exactly what you want, but this sub will give the colorindex in
    > column A, the corresponding color value (numeric, the RGB value) in column

    B,
    > and will fill the cell in column C with the specified color:
    >
    > Public Sub ShowFillColors()
    >
    > For i = 1 To 56
    > Sheets("Sheet1").Range("A" & i).Value = i
    > Sheets("Sheet1").Range("C" & i).Interior.ColorIndex = i
    > Sheets("Sheet1").Range("B" & i).Value = Sheets("Sheet1").Range("C" &
    > i).Interior.Color
    > Next i
    >
    > End Sub




  8. #8
    Tom Ogilvy
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Set the TakeFocusOnClick property if the command button to false.

    --
    Regards,
    Tom Ogilvy

    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, Mangesh
    >
    > Despite several tries at running your sub, I kept hitting a run-time error
    > 1004
    > "Unable to set the colorindex property of the interior class"
    >
    > Clicking debug highlighted this line:
    > rng.Offset(i, 1).Interior.ColorIndex = i
    >
    > What can I do ?
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    > "mangesh_yadav"

    <[email protected]>
    > wrote in message
    > news:[email protected]...
    > >
    > > Private Sub CommandButton1_Click()
    > > Set rng = Range("A1")
    > > For i = 0 To 50
    > > rng.Offset(i, 0) = i
    > > rng.Offset(i, 1).Interior.ColorIndex = i
    > > Next i
    > > End Sub

    >
    >




  9. #9
    Tom Ogilvy
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Bob forgot to furnish this function to go along with the code:

    Public Function GetRGB(colour As Long, ByRef red, ByRef green, ByRef blue)


    red = colour And &HFF
    green = colour \ 256 And &HFF
    blue = colour \ 256 ^ 2 And &HFF


    End Function




    --

    Regards,

    Tom Ogilvy



    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, Bob
    >
    > Despite several tries at running your sub, I kept hitting:
    > Compile error: Sub or Function not defined
    >
    > and "GetRGB" was highlighted in the line:
    > tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    >
    > What can I do ?
    >
    > > By fill colour, do you mean the RGB equivalent?

    > Actually, I'm afraid I don't know <g>. Am new at this.
    >
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    > "Bob Phillips" <[email protected]> wrote in message
    > news:#[email protected]...
    > > Hi Max,
    > >

    >
    > >
    > > Public Sub Colours()
    > > Dim i As Long
    > > Dim tmp, tRed, tBlue, tGreen
    > >
    > > For i = 1 To 56
    > > Cells(i, "A").Value = i
    > > Cells(i, "C").Interior.ColorIndex = i
    > > tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    > > Cells(i, "B").Value = "RGB(" & tRed & ", " & tGreen & ", " &

    tBlue
    > &
    > > ")"
    > > Next i
    > > Columns("B:B").AutoFit
    > >
    > > End Sub

    >
    >




  10. #10
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    "Tom Ogilvy" <[email protected]> wrote in message
    > Set the TakeFocusOnClick property if the command button to false.


    Thanks, Tom !
    Yes, that did it ..
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----



  11. #11
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    "Tom Ogilvy" <[email protected]> wrote
    > Bob forgot to furnish this function to go along with the code:
    > Public Function GetRGB(colour As Long, ByRef red, ByRef green, ByRef blue)
    > red = colour And &HFF
    > green = colour \ 256 And &HFF
    > blue = colour \ 256 ^ 2 And &HFF
    > End Function


    Thanks, Tom (again) !
    Yes, that did it here, too !
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----



  12. #12
    Bob Phillips
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Sorry Max, muissed that function. Here it is

    Public Function GetRGB(colour As Long, ByRef red, ByRef green, ByRef blue)

    red = colour And &HFF
    green = colour \ 256 And &HFF
    blue = colour \ 256 ^ 2 And &HFF

    End Function


    --
    HTH

    Bob Phillips

    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, Bob
    >
    > Despite several tries at running your sub, I kept hitting:
    > Compile error: Sub or Function not defined
    >
    > and "GetRGB" was highlighted in the line:
    > tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    >
    > What can I do ?
    >
    > > By fill colour, do you mean the RGB equivalent?

    > Actually, I'm afraid I don't know <g>. Am new at this.
    >
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    > "Bob Phillips" <[email protected]> wrote in message
    > news:#[email protected]...
    > > Hi Max,
    > >

    >
    > >
    > > Public Sub Colours()
    > > Dim i As Long
    > > Dim tmp, tRed, tBlue, tGreen
    > >
    > > For i = 1 To 56
    > > Cells(i, "A").Value = i
    > > Cells(i, "C").Interior.ColorIndex = i
    > > tmp = GetRGB(ActiveWorkbook.Colors(i), tRed, tGreen, tBlue)
    > > Cells(i, "B").Value = "RGB(" & tRed & ", " & tGreen & ", " &

    tBlue
    > &
    > > ")"
    > > Next i
    > > Columns("B:B").AutoFit
    > >
    > > End Sub

    >
    >




  13. #13
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    "Bob Phillips" <[email protected]> wrote
    > Sorry Max, muissed that function. Here it is ...

    It's ok, Bob. Got the missing piece from Tom just now
    Thanks for the response !
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----



  14. #14
    Mangesh Yadav
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Hi Max,

    If you run this macro through a standard module, you would get an error. Run
    it through the module of the sheet in question. For standard module, you
    need to reference the range with its parent sheet, and thats why you get an
    error.

    Mangesh



    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, Mangesh
    >
    > Despite several tries at running your sub, I kept hitting a run-time error
    > 1004
    > "Unable to set the colorindex property of the interior class"
    >
    > Clicking debug highlighted this line:
    > rng.Offset(i, 1).Interior.ColorIndex = i
    >
    > What can I do ?
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    > "mangesh_yadav"

    <[email protected]>
    > wrote in message
    > news:[email protected]...
    > >
    > > Private Sub CommandButton1_Click()
    > > Set rng = Range("A1")
    > > For i = 0 To 50
    > > rng.Offset(i, 0) = i
    > > rng.Offset(i, 1).Interior.ColorIndex = i
    > > Next i
    > > End Sub

    >
    >




  15. #15
    Max
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    "Mangesh Yadav" wrote:
    > If you run this macro through a standard module,
    > you would get an error. Run it through the module
    > of the sheet in question. For standard module, you
    > need to reference the range with its parent sheet,
    > and thats why you get an error...


    Hi, I got your sub to work on a command button? drawn on a sheet
    but only with the setting done as advised by Tom earlier, i.e.:
    "Set the TakeFocusOnClick property of the command button to False"
    (this might be due to my xl97 version?)

    I did change the line: "For i = 0 To 50" a little to: "For i = 1 To 56"
    though, for consistency with the suggestions by the other responders

    Thanks
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----



  16. #16
    Mangesh Yadav
    Guest

    Re: Sub to list colorindexes and the corresponding fill colours

    Glad that it worked. Thanks for the feedback.

    Mangesh



    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > "Mangesh Yadav" wrote:
    > > If you run this macro through a standard module,
    > > you would get an error. Run it through the module
    > > of the sheet in question. For standard module, you
    > > need to reference the range with its parent sheet,
    > > and thats why you get an error...

    >
    > Hi, I got your sub to work on a command button? drawn on a sheet
    > but only with the setting done as advised by Tom earlier, i.e.:
    > "Set the TakeFocusOnClick property of the command button to False"
    > (this might be due to my xl97 version?)
    >
    > I did change the line: "For i = 0 To 50" a little to: "For i = 1 To 56"
    > though, for consistency with the suggestions by the other responders
    >
    > Thanks
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1