Solved

Problem with While...Wend Loop

Posted on 2013-11-07
12
281 Views
Last Modified: 2013-12-03
Hi Guys, I am getting an Error code "Type Mismatch" when I run this "While...Wend" Loop I just written. Can anyone tell me why? File is attached
Dummyfile.xlsm
0
Comment
Question by:Justincut
[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
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39630857
You can't change two things at once as you try to do in lines 1 and 6 here.
Cells(i, 30).Value = "On dashboard - non-validated trade" And Cells(i, 31).Value = "BAU - Dashboard"



ElseIf Cells(i, 54).Value <> "" Then
Cells(i, 30).Value = "On dashboard - f/e error" And Cells(i, 31).Value = "BAU - Dashboard"

Open in new window


Do this instead
Cells(i, 30).Value = "On dashboard - non-validated trade"
Cells(i, 31).Value = "BAU - Dashboard"



ElseIf Cells(i, 54).Value <> "" Then
Cells(i, 30).Value = "On dashboard - f/e error" 
Cells(i, 31).Value = "BAU - Dashboard"

Open in new window

0
 
LVL 34

Expert Comment

by:Norie
ID: 39630862
Try this.
Sub Nonvalidated()
Dim I As Long

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    I = 4

    While Cells(I, 5).Value <> ""

        I = I + 1

        If Not IsError(Cells(I, 53).Value) Then
            Cells(I, 30).Value = "On dashboard - non-validated trade"
            Cells(I, 31).Value = "BAU - Dashboard"
        ElseIf Cells(I, 54).Value <> "" Then
            Cells(I, 30).Value = "On dashboard - f/e error"
            Cells(I, 31).Value = "BAU - Dashboard"
        End If
    Wend
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    
End Sub

Open in new window

0
 

Author Comment

by:Justincut
ID: 39630872
Hi I am still getting Runtime Error "13 Type Mismatch on this bit of code
"If Cells(i, 53).Value <> "#N/A" Then"

Any ideas why?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39630883
You can also replace the "And" with a colon    :
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39630888
Change to

"If Cells(i, 53).text <> "#N/A" Then"
0
 
LVL 34

Expert Comment

by:Norie
ID: 39630907
Did you try the code I posted?

It should take care of both problems.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39637686
If you click the link supplied by Jusincut you see my objection which was
The Asker assigned all the points to the question he asked in pots ID 39630872 rather than to the answer to the original question which was given in the first two answers. At the very least the points should be split 3 ways.
My preference would be for the points to be split between imnorie and me but I'll be happy with a three way split,
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39638665
MartinLiss, I disagree here. Your solution was not complete. It did not take care of the #NA part which was the first error when the code is run.

imnorie's code, however was complete. So was mine in two parts although it came in after imnorie's.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39638702
You are right, my response did not address the #NA part but that was not the question that was asked, rather the question that was asked concerned the Type Mismatch error and that's what I responded to.

Having said that however I don't want to argue over this, and whatever the Asker and/or the moderator decide is fine with me.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39693893
Ok as is. You win some and you lose some.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

617 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