mardi 30 août 2016

Visual Basic: Else-Ifs with For loops stopping after first For loop

I have a series of If, Then, ElseIfs checking through rows in this worksheet. It looks to see if the entire is not zero, but looking for the sum of cells to not be zero, then checks for any other zeroes in the row. Essentially in each row, if there any values, I want to make sure that ALL values are filled in. What I have for now is this:

ElseIf Application.WorksheetFunction.Sum(CashL1) <> 0 Then Dim i As Integer For i = 2 To 10 If Cells(8, i).Value = 0 Then Cancel = True MsgBox ("Values missing in *this section* at " & Chr$(i + 64) & 8) End If Next i MsgBox "CashL1: Good"

This works great once, however I have another block of the same kind immediately following it with:

'******************************************************************************

ElseIf Application.WorksheetFunction.Sum(CashL2) <> 0 Then Dim j As Integer For j = 2 To 10 If Cells(9, j).Value = 0 Then Cancel = True MsgBox ("Values missing in *this other section* at " & Chr$(j + 64) & 9) End If Next j MsgBox "CashL2: Good"

I added the MsgBox saying "CashL(1/2): Good" so I could see what it was doing. It appears to only be going through the first one successfully and then showing the MsgBox, unfortunately after that, it ends. It never even makes it to the next section: CashL2. Am I overlooking something somewhere? I am still a VB beginner obviously, so I'm still trying to figure out how to correct myself.

Aucun commentaire:

Enregistrer un commentaire