+ Reply to Thread
Results 1 to 4 of 4

Colour and Pattern Formatting Cells

  1. #1
    Dave M
    Guest

    Colour and Pattern Formatting Cells

    I've got a list of 37 condition statements which i've combined into a
    valdiated drop down list, but I need the cell adjacent to the list to dispaly
    one of 37 unique colour a pattern combinations to allow mutiple selections on
    the sheet to be easily read to assess commonality. Any sugestions as to how I
    do this, I'm pretty new to VB in Excel2003.

    Simplest case is an 8Rx2C matrix with column 1 being the output in terms of
    shading and patterns and column 2 being the drop down selection.

    Thanks for any help
    Dave

  2. #2
    Martin
    Guest

    RE: Colour and Pattern Formatting Cells

    Just a couple of pointers:

    To get code for a particular colour/pattern, just use the recorder (Tools,
    Macro, Record New Macro) and tidy as necessary.

    To colour according to a multiple selection, use a loop combined with If, eg:

    Sub MultipleFormat()
    Dim myCell As Range
    For Each myCell In Selection
    If myCell.Value = [...] Then
    Cells(myCell.Row, 1).Font.ColorIndex = [...]
    ElseIf myCell.Value = [...] Then
    [...]
    Else
    [...]
    End If
    Next
    End Sub

    Hope that helps.

    "Dave M" wrote:

    > I've got a list of 37 condition statements which i've combined into a
    > valdiated drop down list, but I need the cell adjacent to the list to dispaly
    > one of 37 unique colour a pattern combinations to allow mutiple selections on
    > the sheet to be easily read to assess commonality. Any sugestions as to how I
    > do this, I'm pretty new to VB in Excel2003.
    >
    > Simplest case is an 8Rx2C matrix with column 1 being the output in terms of
    > shading and patterns and column 2 being the drop down selection.
    >
    > Thanks for any help
    > Dave


  3. #3
    Peter T
    Guest

    Re: Colour and Pattern Formatting Cells

    Hi Dave,

    Following assumes you have named a range for your DV list "mylist" and a
    range for your formats named "formats". The range "formats" would be in the
    column left of "mylist" and same size, though it could be anywhere. Also
    assumes your dropdown list is in D5 and by adjacent you mean one cell to the
    right.

    In the Worksheet module (rt-click sheet tab > view code

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim vRow
    Dim vClrIdx
    On Error GoTo errH
    If Target.Address = "$D$5" Then ' address of the DV dropdown list
    vRow = Application.Match(Target.Value, Range("mylist"), 0)
    If IsNumeric(vRow) Then
    vClrIdx = Range("formats")(vRow, 1).Value
    If IsNumeric(vClrIdx) = False Or vClrIdx < 1 Or vClrIdx > 56
    Then
    vClrIdx = xlNone
    End If
    End If
    Target.Offset(, 1).Interior.ColorIndex = vClrIdx
    End If
    errH:
    End Sub

    This assumes you have entered colorindex numbers in the range "formats". If
    instead you have actually formated cells in "formats" you could do something
    like

    Target.Offset(, 1).Interior.ColorIndex = Range("formats")(vRow,
    1).Colorindex
    and similar for .Pattern and .PatternColorIndex if necessary.

    Would need more error handling.

    Regards,
    Peter T

    "Dave M" <[email protected]> wrote in message
    news:[email protected]...
    > I've got a list of 37 condition statements which i've combined into a
    > valdiated drop down list, but I need the cell adjacent to the list to

    dispaly
    > one of 37 unique colour a pattern combinations to allow mutiple selections

    on
    > the sheet to be easily read to assess commonality. Any sugestions as to

    how I
    > do this, I'm pretty new to VB in Excel2003.
    >
    > Simplest case is an 8Rx2C matrix with column 1 being the output in terms

    of
    > shading and patterns and column 2 being the drop down selection.
    >
    > Thanks for any help
    > Dave




  4. #4
    Dave M
    Guest

    Re: Colour and Pattern Formatting Cells

    Peter T and Martin

    Many thanks, I'll give it a go, I'd got about halfway there but was stuck
    for ideas!
    Dave

    "Peter T" wrote:

    > Hi Dave,
    >
    > Following assumes you have named a range for your DV list "mylist" and a
    > range for your formats named "formats". The range "formats" would be in the
    > column left of "mylist" and same size, though it could be anywhere. Also
    > assumes your dropdown list is in D5 and by adjacent you mean one cell to the
    > right.
    >
    > In the Worksheet module (rt-click sheet tab > view code
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim vRow
    > Dim vClrIdx
    > On Error GoTo errH
    > If Target.Address = "$D$5" Then ' address of the DV dropdown list
    > vRow = Application.Match(Target.Value, Range("mylist"), 0)
    > If IsNumeric(vRow) Then
    > vClrIdx = Range("formats")(vRow, 1).Value
    > If IsNumeric(vClrIdx) = False Or vClrIdx < 1 Or vClrIdx > 56
    > Then
    > vClrIdx = xlNone
    > End If
    > End If
    > Target.Offset(, 1).Interior.ColorIndex = vClrIdx
    > End If
    > errH:
    > End Sub
    >
    > This assumes you have entered colorindex numbers in the range "formats". If
    > instead you have actually formated cells in "formats" you could do something
    > like
    >
    > Target.Offset(, 1).Interior.ColorIndex = Range("formats")(vRow,
    > 1).Colorindex
    > and similar for .Pattern and .PatternColorIndex if necessary.
    >
    > Would need more error handling.
    >
    > Regards,
    > Peter T
    >
    > "Dave M" <[email protected]> wrote in message
    > news:[email protected]...
    > > I've got a list of 37 condition statements which i've combined into a
    > > valdiated drop down list, but I need the cell adjacent to the list to

    > dispaly
    > > one of 37 unique colour a pattern combinations to allow mutiple selections

    > on
    > > the sheet to be easily read to assess commonality. Any sugestions as to

    > how I
    > > do this, I'm pretty new to VB in Excel2003.
    > >
    > > Simplest case is an 8Rx2C matrix with column 1 being the output in terms

    > of
    > > shading and patterns and column 2 being the drop down selection.
    > >
    > > Thanks for any help
    > > Dave

    >
    >
    >


+ 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