Loop Error

Deonvg

New Member
Joined
Feb 4, 2010
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have the below code, which I cannot get to work :mad:, I'm obviously overlooking something here :(. Would someone be able to assist?

Private Sub CheckAmtType()
Dim AmtACAV As Integer
AmtACAV = AmtTypeCheck
Range("E2").Select
Do Until ActiveCell.Value = Empty
If ActiveCell.Value <> "LA" Then
MsgBox "Amount Type AC or AV Incorrect"
ElseIf ActiveCell.Value <> "LV" Then
MsgBox "Amount Type AC or AV Incorrect"
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Last edited:
Hiker95,

Yes I have, didn't see that doing the trick either.

thx
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hiker95,

Seems like Norie's code is only being applied to Range E2 instead of the entire column or until it finds a blanks or empty cell. Might even be on line 3500
thx
Deon
 
Upvote 0
try this
Code:
Option Explicit
Sub CheckAmtType()
    Dim LR As Long, i As Long
    LR = Cells(Rows.Count, 5).End(xlUp).Row
    For i = 2 To LR
        If Cells(i, 5) <> "LV" And Cells(i, 5) <> "LA" Then
            Cells(i, 5).Select
            MsgBox "Amount Type AC or AV Incorrect in row " & i
            Exit Sub
        End If
    Next i
End Sub
 
Upvote 0
The code I posted works for the data you posted, or it does work when a value is changed in column E.

All the values in your data are LV or LA, so the messagebox will never get called otherwise.
 
Upvote 0
Hiker95 and Norie,

Thank you very much for your reply, Sorry yes, Norie and Hiker95's (last code) works perfectly.

Indeed if you dont have any other amount type the message box will not appear, ONLY unless you have a AC or AV for argument. That is exaclt what it's suppose to do. As the file should only contain LA's or LV's inorder for the uplaod to work correctly, if it doens't it could jeopordise other results.

Thx so much
 
Upvote 0
Hi,

I have also managed to get another code to work.

Private Sub CheckAmt()
Range("E2").Select
Do While Not IsEmpty(ActiveCell)
If ActiveCell.Value <> "LA" And ActiveCell.Value <> "LV" Then
MsgBox "Amt Type must be LA or LV"
End
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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