Results 1 to 2 of 2

Thread: VBA - Wrong results for a for next loop.
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jan 2011
    Location
    orlando
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA - Wrong results for a for next loop.

    Hello.
    This code do not give me any error return; but do not give me the right results either.
    I am trying to get the total of oranges sold only, on "C1". My data Fruit's names A, and quantity sold B
    and this is the code I tried.
    Code:
    Sub Fr_Sd()       
      Dim LastRow As Long
                      LastRow = Cells(Rows.Count, 1).End(xlUp).Row
             Dim i As Long, Total As Long
                      For i = 2 To LastRow
                               If Cells(i, 1).Value = "Oranges" Then
                               Total = Total + Cells(i, 2).Value
                               End If
                      Next i
    Range("C1").Value = Total
    End Sub
    Code:
        
    Fruits Sold
    apples 8
    bananas 16
    oranges 24
    pears 32
    mangos 40
    papayas 48
    mangos 56
    oranges 64
    oranges 72
    apples 80
    oranges 88
    bananas 96
    mangos 104
    papayas 112
    mangos 120
    oranges 128
    oranges 136
    apples 144
    oranges 152
    Last edited by montecarlo2012; Jun 19th, 2019 at 09:32 PM.

  2. #2
    Board Regular
    Join Date
    Jan 2011
    Location
    orlando
    Posts
    358
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Wrong results for a for next loop.

    Sorry, False Alarm, I found the mistake. Thanks.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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