Consulting

Results 1 to 2 of 2

Thread: very trivial one - if else condition

  1. #1

    very trivial one - if else condition

    Hi All,

    The .bas(macro) is having following code
    [vba]
    For i = ArraySize To 1 Step -1
    If BarReport = 3 Then
    For j = 1 To NoOfGroups Step 1
    Else
    For j = NoOfGroups To 1 Step -1
    End If
    dsChart.Cells(j + 1, i + 1).Value = DataArr(loopCnt)
    loopCnt = loopCnt - 1
    Next j
    Next i
    [/vba]
    When I'm executing above code, the program throwing compile error "Else without If"

    Can someone please let me know how to correct this problem.

    Regards,
    Sharath.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Is this what you are trying to do?

    [vba]
    For i = ArraySize To 1 Step -1
    If BarReport = 3 Then
    For j = 1 To NoOfGroups Step 1
    dsChart.Cells(j + 1, i + 1).Value = DataArr(loopCnt)
    loopCnt = loopCnt - 1
    Next j
    Else
    For j = NoOfGroups To 1 Step -1
    dsChart.Cells(j + 1, i + 1).Value = DataArr(loopCnt)
    loopCnt = loopCnt - 1
    Next j
    End If
    Next i
    [/vba]

    The problem is that you have the Ifs and For statements mixed together.

Posting Permissions

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