Solved

Problem with While...Wend Loop

Posted on 2013-11-07
12
254 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
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 46

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 33

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 33

Expert Comment

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

It should take care of both problems.
0
 
LVL 46

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 46

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 46

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Fill Blanks with text from another cell 6 25
Excel Drop Down List 13 36
Msgbox tickler 14 33
Formula Help 3 24
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

825 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