Find Exact Value within a string

vladi305

Board Regular
Joined
Jan 12, 2023
Messages
88
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a function looking for a range of 5 columns and one row searching within a range of 5 columns and multiple rows as the pic attached.

The values on the right side are the one that need to be check if they match any of the value on the left side
one row at a time will be search through all the rows on the left side

So my function is giving me errors writing values on the G column
Also maybe there's a better way of writing this

I want to just write on column G if there's a value found either true or how many did it find 2 or 3 values or 4

Function CheckIfAnyWon2(Arg1 As Range, Arg12 As Range) As Double

Dim iCell As Range
Dim varVal As String
Dim varVal2 As String
Dim rangeArgl As String
Dim rangeArgl2 As String
Dim cnt As Integer
rangeArgl = Arg1.Address
rangeArgl2 = Arg12.Address

Dim LookInHere As String
Dim Counter As Integer
Dim SplitCatcher As Variant
Dim strA As String
Dim strBall1 As String
Dim strBall2 As String
Dim strBall3 As String
Dim strBall4 As String
Dim strBall5 As String
Dim strCurrentCellAddress As String
Dim intBallFound As Integer

Dim keepCnt As Integer
Dim intVal As Integer


'numbers selected from range
For Each iCell In Range(rangeArgl).Cells
varVal = varVal & iCell.Value & " "
Next iCell

LookInHere = varVal
SplitCatcher = Split(LookInHere, " ")
For Counter = 0 To UBound(SplitCatcher)
strA = SplitCatcher(Counter)
Select Case Counter
Case 0
strBall1 = strA & " "
Case 1
strBall2 = strA & " "
Case 2
strBall3 = strA & " "
Case 3
strBall4 = strA & " "
Case 4
strBall5 = strA & " "
End Select
Next


cnt = 0
intBallFound = 0
'check through data history
For Each iCell In Range(rangeArgl2).Cells
cnt = cnt + 1

If cnt = 5 Then

varVal2 = varVal2 & iCell.Value
keepCnt = keepCnt + 1
'check string for matches
If InStr(1, varVal2, strBall1) > 0 Then
intBallFound = intBallFound + 1
End If
If InStr(1, varVal2, strBall2) > 0 Then
intBallFound = intBallFound + 1
End If
If InStr(1, varVal2, strBall3) > 0 Then
intBallFound = intBallFound + 1
End If
If InStr(1, varVal2, strBall4) > 0 Then
intBallFound = intBallFound + 1
End If
If InStr(1, varVal2, strBall5) > 0 Then
intBallFound = intBallFound + 1
End If
varVal2 = ""
cnt = 0
If intBallFound > 0 Then
strCurrentCellAddress = "G" & keepCnt
Sheet17.Range(strCurrentCellAddress).Value = intBallFound & ""
End If
'ActiveWorkbook.Sheets("Sheet17").Cells(7, keepCnt).Value = intBallFound
intBallFound = 0
Else
varVal2 = varVal2 & iCell.Value & " "


End If


Next iCell



End Function
 

Attachments

  • excel_pic68.jpg
    excel_pic68.jpg
    249 KB · Views: 11

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The InStr function isn't finding the desired value

Let's say I have 21 or 17 on the string

If being looked for 1 it will return true because it found 1 on the 21 or the 17
I added an extra space and it return false on the 17 but on the 21 returns true
 
Upvote 0
I've already try using that Xl2BB and it didn't work for me
 
Upvote 0
The set of numbers on the left side are drawings and the one the right side are numbers chosen
I already have a function working that check if any of the set have won but
Again what need to be accomplished now is how many sets match within that string

If the numbers chosen are 4 - 7 - 11 - 15 - 33 and the drawing is 3 - 7 - 11 - 21 36 then 2 numbers matched
 
Upvote 0
Try to follow my 2nd request in #3: "manual input some expected results", instead of the unworking UDF
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,212
Members
448,874
Latest member
b1step2far

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