Solved

Problem with While...Wend Loop

Posted on 2013-11-07
12
228 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 45

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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 33

Expert Comment

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

It should take care of both problems.
0
 
LVL 45

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 45

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 45

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now