Displaying contents of a cell based on 1st occurance of a colour

Paul Naylor

Board Regular
Joined
Sep 2, 2016
Messages
59
Hi , hoping someone can help

I've got a spreadsheet or orders , order numbers ( column A and dates orders were placed in column B.

Column A is also colour codes to signify the status of the order ( "Yellow" pending, "Green" completed & "Red" cancelled)

Need a formula/VBA which will identify the 1st occurance of a colour , in this case Yellow and then display the contents of the adjacent cell column B i.e. date of the order. ( using excel 97)

Paul
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,301
This macro assumes the colours were inserted manually and not a result of conditional formatting. It will prompt you to enter the colour to search. The colorindex numbers I used in the code are 3 for red, 6 for yellow and 4 for green. If the macro doesn't work for any colour, you have to change the numbers in the code to the actual colorindex numbers of the colours you used.
VBA Code:
Sub FindColour()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, response As String, num As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    response = InputBox("Enter the colour to search: yellow, red or green")
    If response = "" Then Exit Sub
    Select Case response
        Case "yellow"
            num = 6
        Case "red"
            num = 3
        Case "green"
            num = 4
    End Select
    For Each rng In Range("A2:A" & LastRow)
        If rng.Interior.ColorIndex = num Then
            MsgBox rng.Offset(, 1)
            Exit For
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,490
Messages
5,636,630
Members
416,932
Latest member
mm07

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top