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:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Deonvg,

One of your variables is not defined.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Rich (BB code):
Option Explicit
Private Sub CheckAmtType()
Dim AmtACAV As Integer
Dim AmtTypeCheck 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
 
Upvote 0
Well, now that he's defined it, he still needs to assign it a value. I don't see a need for it at all
 
Upvote 0
Deonvg,

One of your variables is not defined.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Rich (BB code):
Option Explicit
Private Sub CheckAmtType()
Dim AmtACAV As Integer
Dim AmtTypeCheck 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
I have added as advised but when I test the code it shows the message box when it comes to the "End If' and thus doesn't loop.

I need the code to check that whole column and if it finds amount types other than La or LV, it should show the message box. If it dosn't find anything else the code should continue and do rest.

Thx for your reply.
 
Upvote 0
Deonvg,

I tested the macro with test data and it worked.

Can we see your data?

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:

If you are not able to give us screenshots, see below in my Signature block: You can upload your workbook to Box Net
 
Upvote 0
Try this.
Code:
Private Sub CheckAmtType()
Dim rng As Range
Dim AmtACAV As Integer
Dim AmtTypeCheck As Integer
 
    AmtACAV = AmtTypeCheck
    
    Set rng = Range("E2")
 
    While rng.Value <> ""
        Select Case rng.Value
        
            Case "LA", "LV"
                ' do nothin
            Case Else
                MsgBox "Amount Type AC or AV Incorrect"
                
        End Select
        
        Set rng = rng.Offset(1, 0)

    Wend
    
End Sub
 
Upvote 0
Solution
rsxchin,

Both variables, according to the code, start off as 0.


Code:
AmtACAV = AmtTypeCheck
 
Upvote 0
What if he changed

Code:
ActiveCell.Offset(1, 0).Select

to

Code:
ActiveCell.Offset(1, 0).activate
 
Upvote 0
rsxchin,

Both variables, according to the code, start off as
Excel Workbook
ABCDEFGH
1Ledg_idaccountcenteryearTypeJanFebMrt
2BNKA060101CORBR2010LA0.000.000.00
3BNKA060103CORBR2010LA0.000.000.00
4BNKA060106CORBR2010LA0.000.000.00
5BNKA060109CORBR2010LA0.000.000.00
6BNKA061107CORBR2010LA0.000.000.00
7BNKA061110CORBR2010LA0.000.000.00
8BNKA061111CORBR2010LV0.000.000.00
9BNKA061112CORBR2010LA0.000.000.00
10BNKI010101CORBR2010LA0.000.000.00
11BNKI010103CORBR2010LV0.000.000.00
12BNKI010106CORBR2010LA0.000.000.00
13BNKI010107CORBR2010LA0.000.000.00
0.
#VALUE!
Excel 2007
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

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