Results 1 to 7 of 7

IF condition not working

Threaded View

  1. #1
    Registered User
    Join Date
    07-10-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    11

    IF condition not working

    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!
    Last edited by AliGW; 07-10-2018 at 01:42 PM. Reason: Missing code tags added.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SUMIFS condition not working
    By mangolah in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 03-20-2017, 11:14 AM
  2. [SOLVED] Working formulacodes in vba need run by condition
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2015, 05:27 AM
  3. vba is not working on specific condition
    By SHEIKH TALIB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2014, 12:25 PM
  4. [SOLVED] If condition not working with InStrRev
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 06:40 AM
  5. Join condition not working in VBA
    By cruise.alter in forum Access Tables & Databases
    Replies: 6
    Last Post: 08-01-2012, 08:12 AM
  6. If Condition not working
    By luckyros in forum Excel General
    Replies: 6
    Last Post: 12-16-2011, 05:37 AM
  7. If condition not working in the loop
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2011, 07:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1