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
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,782
Office Version
  1. 2010
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,822
Messages
5,598,304
Members
414,224
Latest member
Crazy_FC

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
Top