samedi 24 octobre 2020

why does my Execl VBA If statement not work

    Private Sub ComboBox1_Change()
    Dim MemberNumArr() As String
    Dim MemberNum As String
    Dim LastRow As Integer
    Dim Milestone As Worksheet
    Dim YouthSheet As Worksheet
    
    Set Milestone = Sheets("Milestone 1")
    Set YouthSheet = Sheets("Youth")
    
    If Milestone.Range("D3").Value Like "* - *" Then
        MemberNumArr = Split([D3].Value, "-")
        MemberNum = MemberNumArr(0)

        LastRow = YouthSheet.Cells(YouthSheet.Rows.Count, "A").End(xlUp).Row
        For r = 3 To LastRow
            If YouthSheet.Range("A" & r).Value Like MemberNum Then
                MsgBox MemberNum
                Milestone.Range("D13").Value = YouthSheet.Range("H" & r).Value ' Loads up Total Participates
                Milestone.Range("D18").Value = YouthSheet.Range("I" & r).Value ' Loads up Total Assists
                Milestone.Range("D23").Value = YouthSheet.Range("J" & r).Value ' Loads up Total Leads
            End If
        Next
    End If
                
End Sub

In cell D3 it Appears as 123456 - Joe Bloggs. I have moved the Msgbox Membernum around to find out where it stops. It gets 123456, and then in my If YouthSheet.Range like/= MemberNum then, it stops there. Doesn't find it, even though it does match.

Just trying to figure out where I'm going wrong. I'm obviously overlooking it, and sometimes a fresh set of eyes will spot something I'm missing!

Thanks!

Aucun commentaire:

Enregistrer un commentaire