VB6 - Find value

Hi

I have a form with 2 MSHFlexgrids.

What i need to do is to find the names from MSHFlexgrid2 into the MSHFLexgrid1 and add the year from the MSHFlexgrid1 in MSHFlexgrid2 based on the name.

I'm getting no results with the below code so far.

Can you please help me with it?
Thanks for your help.

Find
Private Sub cmdFind_Click()
Dim r1 As Long, r2 As Long, i As Long
    Dim Text1 As String
    Dim Text2 As String
    Dim bFound As Boolean

    'Part 1
    For r1 = 1 To MSHFlexGrid2.Rows - 1
        bFound = False
        For r2 = 1 To MSHFlexGrid1.Rows - 1
            Text1 = UCase(MSHFlexGrid2.TextMatrix(r1, 2))
            Text2 = UCase(MSHFlexGrid1.TextMatrix(r2, 3))
            If Text2 = Text1 Then
                bFound = False
                Exit For
            Else
                bFound = True
            End If
        Next r2


        If bFound Then
            MSHFlexGrid2.TextMatrix(r1, 3) = UCase(MSHFlexGrid1.TextMatrix(r2, 5))

        Else


        End If
    Next r1

End Sub

Open in new window

Lookup.zip
LVL 11
Wilder1626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wilder1626Author Commented:
I found out, but i don't know if there is a better way to do this.

Private Sub cmdFind_Click()
Dim r1 As Long, r2 As Long, i As Long
    Dim Text1 As String
    Dim Text2 As String
    Dim bFound As Boolean

    'Part 1
    For r1 = 1 To MSHFlexGrid2.Rows - 1
        bFound = False
        For r2 = 1 To MSHFlexGrid1.Rows - 1
            Text1 = UCase(MSHFlexGrid2.TextMatrix(r1, 2))
            Text2 = UCase(MSHFlexGrid1.TextMatrix(r2, 3))
            If Text2 = Text1 Then
                bFound = False
                Exit For
            Else
                bFound = True
            End If
        Next r2


        If bFound Then
            
        Else
      
MSHFlexGrid2.TextMatrix(r1, 3) = UCase(MSHFlexGrid1.TextMatrix(r2, 5))

        End If
    Next r1

End Sub

Open in new window

Martin LissOlder than dirtCommented:
That code doesn't work.

Private Sub cmdFind_Click()
    Dim r1 As Long, r2 As Long
    Dim bFound As Boolean

    'Part 1
    For r1 = 1 To MSHFlexGrid1.Rows - 1
        bFound = False
        For r2 = 1 To MSHFlexGrid2.Rows - 1
            If UCase(MSHFlexGrid1.TextMatrix(r1, 3)) = UCase(MSHFlexGrid2.TextMatrix(r2, 2)) Then
                bFound = True
                MSHFlexGrid2.TextMatrix(r2, 3) = UCase(MSHFlexGrid1.TextMatrix(r1, 5))
                Exit For
            End If
        Next r2
        If Not bFound Then
            MsgBox "'" & MSHFlexGrid1.TextMatrix(r1, 3) & "' was not found in MSHFlexGrid2"
        End If
    Next r1

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wilder1626Author Commented:
Thanks for your help, it even goes faster then the code i was given.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.