Wend without While?

Chrisjd2

Board Regular
Joined
Mar 1, 2016
Messages
61
Hi, I'm fairly new to VBA so bare with me :)

I don't understand why it it throwing up this error when you can clearly see a While followed by Wend?

Compile Error: Wend without While

'Check
counter = 2
While wsMaster.Cells(counter, 2) <> ""


If IsError(Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:B"), 1, False)) = False Then
'checks if it has been deleted


If IsError(Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:B"), 1, False)) = False Then
'checks if it is a new part
If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 3, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 3, False) Then
wsMaster.Cells(counter, 4).Interior.Color = RGB(255, 155, 0)
If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 4, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 4, False) Then
wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 5, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 5, False) Then
wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 6, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 6, False) Then
wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
End If




End If
counter = counter + 1
Wend
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
If you indent your code, you can see the problem:

Code:
  While wsMaster.Cells(counter, 2) <> ""
    If IsError(Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:B"), 1, False)) = False Then
      'checks if it has been deleted

      If IsError(Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:B"), 1, False)) = False Then
        'checks if it is a new part
        If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 3, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 3, False) Then
          wsMaster.Cells(counter, 4).Interior.Color = RGB(255, 155, 0)
          If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 4, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 4, False) Then
            wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
            If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 5, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 5, False) Then
              wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
              If (Application.VLookup(wsMaster.Cells(counter, 2).Value, wsUpdate.Range("B:G"), 6, False)) <> Application.VLookup(wsUpdate.Cells(counter, 2).Value, wsMaster.Range("B:G"), 6, False) Then
                wsMaster.Cells(counter, 5).Interior.Color = RGB(255, 155, 0)
              End If

            End If
            counter = counter + 1
          Wend
        End Sub
Every Wend should align with While, every If with End If, every With with End With, ...

See http://www.oaltd.co.uk/indenter/indentpage.asp
 
Last edited:
Upvote 0

Forum statistics

Threads
1,218,756
Messages
6,144,301
Members
450,536
Latest member
DavidRankin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top