Solved

Type Mismatch error Excel VBA

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

832 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