Good evening all,
I am trying to run a basic IF condition with a loop. But VBA is giving some unexpected results.
See data below, if the data columns become misaligned, then my sincere apologies.
If Distribution channel is 99, I want Comments to say "No Door". If Distribution channel is 0, I want comments to say "Door". Please note the top left "cell" is with 0 value is cell Y3, which is the starting point for my code.
Door Distribution Channel Comments
0 99
960353 0
960353 0
960673 0
960673 0
0 99
0 99
Sub looptest()
Dim DistChannel As Integer
Dim Comment As String
Range("Y3").Select
Do Until ActiveCell.Value = ""
ActiveCell.Offset(0, 1).Value = DistChannel
If DistChannel = 99 Then
Comment = "No Door"
ElseIf DistChannel = 0 Then
Comment = "Door"
Else: Comment = "Error"
End If
ActiveCell.Offset(0, 2).Value = Comment
ActiveCell.Offset(1, 0).Select
Loop
End Sub
For some strange reason, this sub routine changes the value of the distribution channel to value 0, instead of testing whether the value is 0 or 99. This is the outcome of the sub routine.
Door Distribution Channel Comments
0 0 Door
960353 0 Door
960353 0 Door
960673 0 Door
960673 0 Door
0 0 Door
0 0 Door
Could anyone please explain why it is changing the value of the distribution channel instead of testing it? Many thanks!
Bookmarks