dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Else without If error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    553

    Resolved [RESOLVED] Else without If error

    Following If...Else...End If gives error. Why

    Code:
    If Check3.Value = 1 Then
      Do
        color = RGB(Int(255 * Rnd) + 1, Int(255 * Rnd) + 1, Int(255 * Rnd) + 1)
      While color = vbBlack Or color = vbWhite
    Else
      color = vbGreen
    End If

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,704

    Re: Else without If error

    The correct syntax is:
    Do
    Loop While

    https://www.tutorialspoint.com/vba/v...while_loop.htm

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,034

    Re: Else without If error

    Yep, also can use Do While Or Do Until.

    The code posted as written has two open loops do without loop and while without wend

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width