+ Reply to Thread
Results 1 to 4 of 4

Drop Down list with color

Hybrid View

  1. #1
    Registered User
    Join Date
    04-22-2022
    Location
    volos
    MS-Off Ver
    office 365 & Office 365 for MAC
    Posts
    24

    Thumbs up Drop Down list with color

    Hi, I am new to excel vba and need your help.

    My table consist of several lines like the example I attach.

    I want to automatically create a drop list or update an already created one when the code (loop? I dont know) finds color Grey . Then pick the name of that cell and create a new item at drop down in order when select it to go to that cell.

    Is this possible?

    Cheers!
    Attached Files Attached Files

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Drop Down list with color

    So, you need 2 macros.

    1st to create/update dropdown list, into standard module:

    Sub RefreshDropDown()
    Dim AStr As String
    Dim cell As Range
    With Sheet9
        For Each cell In .Range("B2:C150")
            If cell.Interior.Color = 12566463 Then AStr = AStr & "," & cell.Value
        Next cell
        AStr = Right(AStr, Len(AStr) - 1)
        With .Range("B2").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=AStr
        End With
    End With
    End Sub
    I do not understand that how do you want to trigger it to rebuild but it will create drop-down in B2 with values from grey cells.

    2nd into sheet code (based on chosen value from drop-down, value is found and select):

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, [B2]) Is Nothing Then
        With ActiveSheet.Range("B2:C150")
            Set c = .Find(Target.Value, LookIn:=xlValues)
            If Not c Is Nothing Then
                c.Select
            End If
        End With
    End If
    End Sub
    Attached Files Attached Files
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Registered User
    Join Date
    04-22-2022
    Location
    volos
    MS-Off Ver
    office 365 & Office 365 for MAC
    Posts
    24

    Re: Drop Down list with color

    Dear KOKOSE

    Thank you for your reply!

    I was wondering if this can be done with range of cells , ie B12:B1000 and I12:1000 I tried but no luck.
    Last edited by AliGW; 04-25-2022 at 03:34 AM. Reason: PLEASE don't quote unnecessarily!

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Drop Down list with color

    Do you mean instead of
    For Each cell In .Range("B2:C150")
    check colours also in other ranges (B12:B1000 and I12:I10000)?

    Try like this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Set rng1 = Union(Range("B2:C150"), Range("B12:B1000"), Range("I12:I1000"))
    If Not Intersect(Target, [B2]) Is Nothing Then
        With rng1
            Set c = .Find(Target.Value, LookIn:=xlValues)
            If Not c Is Nothing Then
                c.Select
            End If
        End With
    End If
    End Sub
    Sub RefreshDropDown()
    Dim AStr As String
    Dim cell As Range
    Set rng1 = Union(Range("B2:C150"), Range("B12:B1000"), Range("I12:I1000"))
    With Sheet9
        For Each cell In rng1
            If cell.Interior.Color = 12566463 Then AStr = AStr & "," & cell.Value
        Next cell
        AStr = Right(AStr, Len(AStr) - 1)
        With .Range("B2").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=AStr
        End With
    End With
    End Sub
    Attached Files Attached Files
    Last edited by KOKOSEK; 04-25-2022 at 03:46 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Color Image in Drop Down List
    By adman42 in forum Excel General
    Replies: 14
    Last Post: 07-04-2014, 09:36 AM
  2. Color Coding in a Drop Down List
    By Don in forum Excel General
    Replies: 6
    Last Post: 10-06-2012, 04:00 AM
  3. Excel 2007 : How to Create a Color Drop Down List
    By Kath7889 in forum Excel General
    Replies: 1
    Last Post: 09-25-2011, 02:46 PM
  4. How to Create a Color Drop Down List
    By Kath7889 in forum Excel General
    Replies: 2
    Last Post: 09-24-2011, 05:22 PM
  5. help to highlight/color a drop-down list
    By alancauchi in forum Excel General
    Replies: 3
    Last Post: 12-30-2009, 09:52 AM
  6. How to very color in drop down list
    By cat123 in forum Excel General
    Replies: 2
    Last Post: 05-15-2007, 10:18 AM
  7. Drop down list (color)
    By jimz97 in forum Excel General
    Replies: 1
    Last Post: 03-14-2007, 11:36 AM

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