Solved

Type Mismatch error Excel VBA

Posted on 2013-12-28
3
780 Views
Last Modified: 2013-12-28
The Do While line keeps giving error message "Type Mismatch".



Sub MostActiveDayPrediction()

    Dim r As Integer
    Dim rng As Excel.Range
    
    Sheets("Stats").Activate
    r = 1
    Set rng = Sheets("Yahoo_Download_2").Range("Results_OEX")
    Do While rng.Offset(r, 0) <> ""
        If rng.Offset(r, 0) = Sheets("Stats").Range("Last_Monday") Then Stop
        r = r + 1
    Loop

End Sub

Open in new window

0
Comment
Question by:rrhandle8
[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
  • 2
3 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 39744363
I can reproduce that Type Mismatch error message if rng.Offset(r, 0) contains an error value
If the cell contains a blank, text or a number, it executes fine.
0
 
LVL 81

Accepted Solution

by:
byundt earned 260 total points
ID: 39744366
Possible workaround:
Sub MostActiveDayPrediction()

    Dim r As Integer
    Dim rng As Excel.Range
    
    Sheets("Stats").Activate
    r = 1
    Set rng = Sheets("Yahoo_Download_2").Range("Results_OEX")
    Do
        If Not IsError(rng.Offset(r, 0)) Then
            If rng.Offset(r, 0) = "" Then Exit Do
        End If
        If rng.Offset(r, 0) = Sheets("Stats").Range("Last_Monday") Then Stop
        r = r + 1
    Loop

End Sub

Open in new window

0
 

Author Closing Comment

by:rrhandle8
ID: 39744375
Thanks, byundt.
I see my mistake.  The range contains multiple rows and columns.  You cannot use .offset when selecting a range that size.  I should have set the range name to just the top left cell.
Thanks for making me think.
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

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 …
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.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

691 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