+ Reply to Thread
Results 1 to 10 of 10

setting cell color

  1. #1
    Wazooli
    Guest

    setting cell color

    I have been using the following code, as posted in this usergroup recently:

    Public Function GetCellColor(MyCell As Range) As Variant
    GetCellColor = MyCell.Interior.ColorIndex
    End Function

    This works great, and allows me to use the cell color as a downstream
    condition. Is there a similarly succint bit of code that will allow me to
    assign a color to a cell via a UDF?

    Thanks,

    Wazooli

  2. #2
    Wazooli
    Guest

    RE: setting cell color

    And, P.S. - I don't want to do this via conditional formatting. I would like
    to learn how to do it with VBA.

    Wazolli

    "Wazooli" wrote:

    > I have been using the following code, as posted in this usergroup recently:
    >
    > Public Function GetCellColor(MyCell As Range) As Variant
    > GetCellColor = MyCell.Interior.ColorIndex
    > End Function
    >
    > This works great, and allows me to use the cell color as a downstream
    > condition. Is there a similarly succint bit of code that will allow me to
    > assign a color to a cell via a UDF?
    >
    > Thanks,
    >
    > Wazooli


  3. #3
    Bob Phillips
    Guest

    Re: setting cell color

    No, because UDFS return a value, they do not change worksheet attributes.

    --
    HTH

    Bob Phillips

    "Wazooli" <[email protected]> wrote in message
    news:[email protected]...
    > And, P.S. - I don't want to do this via conditional formatting. I would

    like
    > to learn how to do it with VBA.
    >
    > Wazolli
    >
    > "Wazooli" wrote:
    >
    > > I have been using the following code, as posted in this usergroup

    recently:
    > >
    > > Public Function GetCellColor(MyCell As Range) As Variant
    > > GetCellColor = MyCell.Interior.ColorIndex
    > > End Function
    > >
    > > This works great, and allows me to use the cell color as a downstream
    > > condition. Is there a similarly succint bit of code that will allow me

    to
    > > assign a color to a cell via a UDF?
    > >
    > > Thanks,
    > >
    > > Wazooli




  4. #4
    Wazooli
    Guest

    Re: setting cell color

    So then there is no way to assign a color to a cell using VBA?

    Wazooli

    "Bob Phillips" wrote:

    > No, because UDFS return a value, they do not change worksheet attributes.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > "Wazooli" <[email protected]> wrote in message
    > news:[email protected]...
    > > And, P.S. - I don't want to do this via conditional formatting. I would

    > like
    > > to learn how to do it with VBA.
    > >
    > > Wazolli
    > >
    > > "Wazooli" wrote:
    > >
    > > > I have been using the following code, as posted in this usergroup

    > recently:
    > > >
    > > > Public Function GetCellColor(MyCell As Range) As Variant
    > > > GetCellColor = MyCell.Interior.ColorIndex
    > > > End Function
    > > >
    > > > This works great, and allows me to use the cell color as a downstream
    > > > condition. Is there a similarly succint bit of code that will allow me

    > to
    > > > assign a color to a cell via a UDF?
    > > >
    > > > Thanks,
    > > >
    > > > Wazooli

    >
    >
    >


  5. #5
    Peo Sjoblom
    Guest

    Re: setting cell color

    That's not what you asked and what Bob answered to, you asked if it was
    possible using a UDF
    to use a macro see:

    http://www.mvps.org/dmcritchie/excel/colorrng.htm

    http://www.mvps.org/dmcritchie/excel/colors.htm

    --
    Regards,

    Peo Sjoblom

    (No private emails please, for everyone's
    benefit keep the discussion in the newsgroup/forum)



    "Wazooli" <[email protected]> wrote in message
    news:[email protected]...
    > So then there is no way to assign a color to a cell using VBA?
    >
    > Wazooli
    >
    > "Bob Phillips" wrote:
    >
    >> No, because UDFS return a value, they do not change worksheet attributes.
    >>
    >> --
    >> HTH
    >>
    >> Bob Phillips
    >>
    >> "Wazooli" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > And, P.S. - I don't want to do this via conditional formatting. I
    >> > would

    >> like
    >> > to learn how to do it with VBA.
    >> >
    >> > Wazolli
    >> >
    >> > "Wazooli" wrote:
    >> >
    >> > > I have been using the following code, as posted in this usergroup

    >> recently:
    >> > >
    >> > > Public Function GetCellColor(MyCell As Range) As Variant
    >> > > GetCellColor = MyCell.Interior.ColorIndex
    >> > > End Function
    >> > >
    >> > > This works great, and allows me to use the cell color as a downstream
    >> > > condition. Is there a similarly succint bit of code that will allow
    >> > > me

    >> to
    >> > > assign a color to a cell via a UDF?
    >> > >
    >> > > Thanks,
    >> > >
    >> > > Wazooli

    >>
    >>
    >>




  6. #6
    Numfric
    Guest

    Re: setting cell color

    Sub Color_red()
    '
    ' Color_red Macro
    ' Set cell color to red
    '

    '
    With Selection.Interior
    .ColorIndex = 3
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With
    End Sub

    "Wazooli" wrote:

    > So then there is no way to assign a color to a cell using VBA?
    >
    > Wazooli
    >
    > "Bob Phillips" wrote:
    >
    > > No, because UDFS return a value, they do not change worksheet attributes.
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > "Wazooli" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > And, P.S. - I don't want to do this via conditional formatting. I would

    > > like
    > > > to learn how to do it with VBA.
    > > >
    > > > Wazolli
    > > >
    > > > "Wazooli" wrote:
    > > >
    > > > > I have been using the following code, as posted in this usergroup

    > > recently:
    > > > >
    > > > > Public Function GetCellColor(MyCell As Range) As Variant
    > > > > GetCellColor = MyCell.Interior.ColorIndex
    > > > > End Function
    > > > >
    > > > > This works great, and allows me to use the cell color as a downstream
    > > > > condition. Is there a similarly succint bit of code that will allow me

    > > to
    > > > > assign a color to a cell via a UDF?
    > > > >
    > > > > Thanks,
    > > > >
    > > > > Wazooli

    > >
    > >
    > >


  7. #7
    Wazooli
    Guest

    Re: setting cell color

    Thanks Peo. I will try to use some of what is on the second link you
    supplied, although you shouldn't be surprised if I am back here asking
    questions.

    wazooli

    "Peo Sjoblom" wrote:

    > That's not what you asked and what Bob answered to, you asked if it was
    > possible using a UDF
    > to use a macro see:
    >
    > http://www.mvps.org/dmcritchie/excel/colorrng.htm
    >
    > http://www.mvps.org/dmcritchie/excel/colors.htm
    >
    > --
    > Regards,
    >
    > Peo Sjoblom
    >
    > (No private emails please, for everyone's
    > benefit keep the discussion in the newsgroup/forum)
    >
    >
    >
    > "Wazooli" <[email protected]> wrote in message
    > news:[email protected]...
    > > So then there is no way to assign a color to a cell using VBA?
    > >
    > > Wazooli
    > >
    > > "Bob Phillips" wrote:
    > >
    > >> No, because UDFS return a value, they do not change worksheet attributes.
    > >>
    > >> --
    > >> HTH
    > >>
    > >> Bob Phillips
    > >>
    > >> "Wazooli" <[email protected]> wrote in message
    > >> news:[email protected]...
    > >> > And, P.S. - I don't want to do this via conditional formatting. I
    > >> > would
    > >> like
    > >> > to learn how to do it with VBA.
    > >> >
    > >> > Wazolli
    > >> >
    > >> > "Wazooli" wrote:
    > >> >
    > >> > > I have been using the following code, as posted in this usergroup
    > >> recently:
    > >> > >
    > >> > > Public Function GetCellColor(MyCell As Range) As Variant
    > >> > > GetCellColor = MyCell.Interior.ColorIndex
    > >> > > End Function
    > >> > >
    > >> > > This works great, and allows me to use the cell color as a downstream
    > >> > > condition. Is there a similarly succint bit of code that will allow
    > >> > > me
    > >> to
    > >> > > assign a color to a cell via a UDF?
    > >> > >
    > >> > > Thanks,
    > >> > >
    > >> > > Wazooli
    > >>
    > >>
    > >>

    >
    >
    >


  8. #8
    Ola
    Guest

    Re: setting cell color

    Is it possible to make this work?

    Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
    MyCell.Interior.ColorIndex = Color
    If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
    End Function

    Ola


  9. #9
    Bob Phillips
    Guest

    Re: setting cell color

    See my reply to Waxooli.

    --
    HTH

    Bob Phillips

    "Ola" <[email protected]> wrote in message
    news:[email protected]...
    > Is it possible to make this work?
    >
    > Public Function ColorCell(MyCell As Range, Color, Optional Message) As

    Variant
    > MyCell.Interior.ColorIndex = Color
    > If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
    > End Function
    >
    > Ola
    >




  10. #10
    Numfric
    Guest

    Re: setting cell color

    Yes (with slight correction):

    Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
    MyCell.Interior.ColorIndex = Color
    If IsEmpty(Message) Then MyCell = "" Else MyCell = Message
    End Function
    Sub Color_red()
    '
    ' Color_red Macro
    ' Set cell color to red
    '

    '
    Dim x As Variant
    x = ColorCell(Range("a2:a7"), 3, "This should be red")
    End Sub

    "Ola" wrote:

    > Is it possible to make this work?
    >
    > Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
    > MyCell.Interior.ColorIndex = Color
    > If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
    > End Function
    >
    > Ola
    >


+ 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