mercredi 8 juin 2016

Else case running even if true (If/Else)

I am currently working with VBA on excel and I could really use some help. As shown below, I'm essentially trying to check all the cells for a specific value (2090) & output "1" if 2090 is found in that row, "0" otherwise. This output will be on 25th column & be in the same row as where the number is.

I did some tests & I know that my code does indeed output "1" when met with 2090 and outputs in the right place etc. However, right after outputting the "1", it'll immediately be overlapped by a "0" again. Therefore, I believe the else case is running even when the If statement is true. At the end of the execution, my whole column just produces a a bunch of "1"s and nothing else.

I would appreciate any kind of help on this! Thank you.

Sub New()
Dim i As Integer, j As Integer, Needed As Integer
intValueToFind = 2090
For i = 1 To 10
For j = 1 To 20
    If Cells(i, j).Value = intValueToFind Then
       Cells(i, 25).Value = "1"
    Else
       Cells(i, 25).Value = "0"

    End If
Next j
Next i
End Sub

Aucun commentaire:

Enregistrer un commentaire