This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Hi Experts using excel 2010

See attached workbook

Need a formula that does the following look the I'd in column A and if we have a Y in column b then find the corresponding Y in range c2:p5 and also if we have a Y in column q and a Y in second data range r2:v5 then return back results as shown in column x.

Book2.xlsx

See attached workbook

Need a formula that does the following look the I'd in column A and if we have a Y in column b then find the corresponding Y in range c2:p5 and also if we have a Y in column q and a Y in second data range r2:v5 then return back results as shown in column x.

Book2.xlsx

=$A2&"("&IF($B2="Y",SUBSTI

If so, the second half (in bold) can be shorter:

=$A2&"("&IF($B2="Y",SUBSTI

Is there a maximum or fixed number of Y entries in Key1 range? With your sample, both entries where there are entries in the Key1 range, there are 3 entries. If we knew that there would only be 3 entries then it could be reduced to checking three ranges based on the placing of the Y.

Alternatively, it could be done with a User Defined Function (UDF). A UDF is basically a bit of VBA that is used in the same way as a formula. This would mean changing the workbook to an xlsm though with the subsequent allowing of macros which that would enforce.

Thanks

Rob H

```
Function CheckKey(Name As Range, Ch1 As Range, Key1 As Range, Res1 As Range, Ch2 As Range, Key2 As Range, Res2 As Range)
If Ch1 = "Y" Then
Str1 = ""
Count1 = 0
For Each Cell In Key1
Count1 = Count1 + 1
Next Cell
For C = 1 To Count1
Check = WorksheetFunction.Index(Key1, 1, C)
If Check = "Y" Then
Result = WorksheetFunction.Index(Res1, 1, C) & Chr(44)
Else
Result = ""
End If
Str1 = Str1 & Result
Result = ""
Next C
Str1 = Left(Str1, Len(Str1) - 1)
If Ch2 = "Y" Then Str1 = Str1 & Chr(47)
End If
If Ch2 = "Y" Then
Str2 = ""
Count2 = 0
For Each Cell In Key2
Count2 = Count2 + 1
Next Cell
For C = 1 To Count2
Check = WorksheetFunction.Index(Key2, 1, C)
If Check = "Y" Then
Result = WorksheetFunction.Index(Res2, 1, C) & Chr(44)
Else
Result = ""
End If
Str2 = Str2 & Result
Result = ""
Next C
Str2 = Left(Str2, Len(Str2) - 1)
End If
CheckKey = Name & "(" & Str1 & Str2 & ")"
End Function
```

It has several input values, they are listed below with the equivalent description and range in your sample workbook:Name As Range - The name to be included at start of final result, column A (ID)

Ch1 As Range - The cell to be checked for Key1 values, column B (Key1)

Key1 As Range - The range of cells containing Y as a result of Key1, columns C to P

Res1 As Range - The range of cells containing the result of Key1, columns C to P (1 to 14)

Ch2 As Range - The cell to be checked for Key2 values, column Q (Key2)

Key2 As Range- The range of cells containing Y as a result of Key2, columns R to V

Res2 As Range - The range of cells containing the result of Key2, columns R to V (Issue 1 to 5)

It is used in the spreadsheet like a formula with the following syntax:

=CheckKey($A2,$B2,$C2:$P2,

$A2 = Name

$B2 = Ch1

$C2:$P2 = Key1

$C$1:$P$1 = Res1

$Q2 = Ch2

$R2:$V2 = Key2

$R$1:$V$1 = Res2

Note the $ locking the row for Res1 and Res2; this will ensure the results are still taken from row 1 when the formula is copied down to more rows.

Any further questions, please let us know.

Thanks

Rob H

Lookup-UDF.xlsm

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

=$A2&"("&IF($B2="Y",IF(C2=

Bit lengthy and it needs tweaking for extra comma after last entry from Key1 range and the "/" between Key1 and Key2 ranges.