Solved

Problem with While...Wend Loop

Posted on 2013-11-07
12
272 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 47

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
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!

 
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 47

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 47

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 47

Expert Comment

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

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

734 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