Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Looping problem

Posted on 2013-10-22
6
Medium Priority
?
135 Views
Last Modified: 2013-10-22
Folks,
The code below is failing me. Here's my objective. In the Range D5:E12 if the value is "Correct" then I execute a module "FormulasOK". If a value <> "Correct" then I execute a module "CheckFormulaFunction".

Dim lRowLoop As Long

For lRowLoop = 5 To 12

 If Cells(lRowLoop, 4).Text = "Correct" Then
     Next lRowLoop
     Else
        CheckFormulaFunction
        Exit Sub
    End If

Open in new window

0
Comment
Question by:Frank Freese
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 24

Assisted Solution

by:Steve
Steve earned 400 total points
ID: 39591177
try:

Dim lRowLoop As Long
For lRowLoop = 5 To 12
 If Cells(lRowLoop, 4).value = "Correct" Then
        call FormulasOK
     Else
        call CheckFormulaFunction
    End If 
 Next lRowLoop

Open in new window

The above code only loops through D5:D12
If you want E5 to E12 you would repeat using Cells(lRowLoop, 5).value

you will need subs or functions called FormulasOK and CheckFormulaFunction
but this should sort out the code logic for you.
0
 
LVL 81

Accepted Solution

by:
byundt earned 1600 total points
ID: 39591189
Did you mean to call FormulasOK only if all cells are Correct?
Sub FormulaChecker()
Dim lRowLoop As Long
For lRowLoop = 5 To 12
    If Cells(lRowLoop, 4).Text <> "Correct" Then
        CheckFormulaFunction
        Exit Sub
    End If
Next
FormulasOK
End Sub

Open in new window

0
 
LVL 24

Assisted Solution

by:Steve
Steve earned 400 total points
ID: 39591212
Ahh, Brad, you may be right there, in that case I would tend to use a Boolean...

Sub FormulaChecker()
Dim lRowLoop As Long
Dim bCorrect as Boolean: bCorrect = True

For lRowLoop = 5 To 12
    If Cells(lRowLoop, 4).Value <> "Correct" Then bCorrect = False
Next
        
If bCorrect then
    FormulasOK
else
    CheckFormulaFunction
end if

End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Frank Freese
ID: 39591341
I've changed Brad's suggestion some. As I read my changes below, what happens is that the first Loop checks for the "Correct" from 5 - 12 column 4. If there's not a "Correct" then CheckFormulaFunction is executed and I execute the sub.
The same thing happens in the seond Loop except it checks column 5. If everything is "Correct" then it executes FormulasOK. Is this new code correct then?

Dim lRowLoop As Long
For lRowLoop = 5 To 12
 If Cells(lRowLoop, 4).value = "Correct" Then
             Else
             CheckFormulaFunction
             Exit sub
    End If 
 Next lRowLoop

For lRowLoop = 5 To 12
 If Cells(lRowLoop, 5).value = "Correct" Then
             Else
             CheckFormulaFunction
             Exit Sub
    End If 
 Next lRowLoop

FormulasOK

Open in new window

0
 

Author Comment

by:Frank Freese
ID: 39591411
The revised code I posted did what I was looking for.
With a few changes to Brads code I felt like he deserved the majority of the points.
But I am grateful for all that chimed in.
0
 

Author Closing Comment

by:Frank Freese
ID: 39591419
thanks everyone.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question