vendredi 17 juillet 2020

Why is VBA reading my ElseIf statement but not executing the code under it?

I have some nested If and ElseIf statements.

The code runs through the if and elseif statements with the st value.

What the code should do is loop through the elseif statements with the first genr value, match the st, store the cap value (62 in this case), calculate the max value for that cap value, and then loop to the next genr value.

I've stepped through it to debug, and it does actually go the elseif line for genr = Q3. However, it skips the new cap value and completes the rest of the code with the old cap value. cap is an integer

Is there something I'm missing?

st = H 'take st=H as an example, genr for it is Q1 and Q3

Gen = o.Cells(cell.Row, "G") 
        
G = Split(Gen, ",") 
        
For k = LBound(G) To UBound(G)

    If Left(Trim(G(k)), 1) = "G" Then
    
    Genr = CStr(G(k))
           
       
    If St = "H" Then
        If Genr = "Q1" Or Genr = "Q2" Then
            cap = 62
        ElseIf Genr = "Q3" Then
            cap = 63
        End If
    ElseIf St = "Wh" Then
        If Genr = "Q1" Or Genr = "Q2" Or Genr = "Q3" Then
            cap = 65
        End If

' and so on for the rest of the st = "" loops
     .
     .
     .

End If

max = c.Cells(cap, "G").Value + max
    
End If 'endif of trim
    
Next k
        

Aucun commentaire:

Enregistrer un commentaire