How to find the first cell containing a "Y"

ds_robb

Board Regular
Joined
Aug 25, 2002
Messages
74
Office Version
  1. 365
Platform
  1. Windows
I have a string of cells that go from Jan-15 to Sep-17 Horizontally (H3 to AZ3) and then below that I have cells across multiple lines (also H to AZ) containing either a Y or N indicating if any data was sent in that month. Does anyone know how I can check on the range to find when the first Y occurs and then report back the corresponding month to cell A


EG:

On line 4, cells H, J, K and L = N and M = Y Thus making the first occurrence of Y at M4 corresponding to cell M3 which is May-15 Therefore data was first transmitted on May 15. Cells N, O and onwards are likely to have Y's ongoing but could also have an N is no data was transmitted that month. I simply need the first Y


Many thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try:
You may need to format cell A1 as date.
Excel Workbook
ABHIJKLMNO
15/15/2018
2
31/1/20182/5/20183/16/20184/5/20184/30/20185/15/20185/25/20186/1/2018
4NNNNNYNY
Sheet
 
Upvote 0
Here is a VBA solution

Code:
Option Explicit


Sub FindY()
    Dim c As Range
    Dim rng As Range
    Dim x As Date
    Set rng = Range("H4:AZ4")
    For Each c In rng
        If c = "Y" Then
            x = c.Offset(-1, 0)
        End If
    Next c
    MsgBox ("Your First Y is " & x)
    Exit Sub


End Sub
 
Upvote 0
Hi Alan I think you need to move the lines below into the If statement as if there is more than one "Y" the code as is will give the message box for the last "Y".

Code:
    MsgBox ("Your First Y is " & x)
    Exit Sub
 
Upvote 0
I have a string of cells that go from Jan-15 to Sep-17 Horizontally (H3 to AZ3) and then below that I have cells across multiple lines (also H to AZ) containing either a Y or N indicating if any data was sent in that month. Does anyone know how I can check on the range to find when the first Y occurs and then report back the corresponding month to cell A

EG:

On line 4, cells H, J, K and L = N and M = Y Thus making the first occurrence of Y at M4 corresponding to cell M3 which is May-15 Therefore data was first transmitted on May 15. Cells N, O and onwards are likely to have Y's ongoing but could also have an N is no data was transmitted that month. I simply need the first Y
You have more than one row of N's and Y's, correct? And you want the date for the first Y in Column A for the row that Y is on, correct? If so, give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub FirstWyes()
  Dim R As Long, Dates As Variant, Data As Variant, Result As Variant
  Dates = Range("H3:AZ3")
  Data = Intersect(Columns("H:AZ"), Range("4:" & Cells(Rows.Count, "H").End(xlUp).Row))
  ReDim Result(1 To UBound(Data), 1 To 1)
  On Error Resume Next
  For R = 1 To UBound(Data)
    Result(R, 1) = Dates(1, InStr(Join(Application.Index(Data, R, Evaluate("TRANSPOSE(ROW(1:45))")), ""), "Y"))
  Next
  On Error GoTo 0
  Range("A4").Resize(UBound(Result)) = Result
  Columns("A").AutoFit
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,737
Members
449,185
Latest member
hopkinsr

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