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

Paul Naylor

Board Regular
Joined
Sep 2, 2016
Messages
98
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
  2. Mobile
  3. Web
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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
Back
Top