Solved

Problem with While...Wend Loop

Posted on 2013-11-07
12
264 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 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 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
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!

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

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

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…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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