Solved

Type Mismatch error Excel VBA

Posted on 2013-12-28
3
771 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

827 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