Runtime Error "Type Mismatch"

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am receiving a type mismatch error on the following line. Not sure why this is occurring.

Are there limitations on the properties that I can establish within the row and column values? For instance is "A+3" as a row value not acceptable when being compared with an integer variable alone "A".


Code:
If Cells(A, "E").Value > Cells((A + 1), "E").Value And Cells((A + 2), "E").Value And Cells((A + 3), "E").Value And Cells((A + 4), "E").Value And Cells((A + 5), "E").Value And Cells((A + 6), "E").Value And Cells((A + 7), "E").Value And Cells((A + 8), "E").Value And Cells((A + 9), "E").Value And Cells((A + 10), "E").Value And Cells((A - 1), "E").Value And Cells((A - 2), "E").Value And Cells((A - 3), "E").Value And Cells((A - 4), "E").Value And Cells((A - 5), "E").Value And Cells((A - 6), "E").Value And Cells((A - 7), "E").Value And Cells((A - 8), "E").Value And Cells((A - 9), "E").Value And Cells((A - 10), "E").Value Then

Thanks, SBF12345
 
I noticed that the line

Code:
[COLOR=#333333]Application.Large(Cells((A - 10), "E").Resize(21), 2)[/COLOR]

doesn't include a ".value" property. How can I direct the range of cells to look at cell values?
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I noticed that the line

Code:
[COLOR=#333333]Application.Large(Cells((A - 10), "E").Resize(21), 2)[/COLOR]

doesn't include a ".value" property. How can I direct the range of cells to look at cell values?

This is the same as calling the Large function in Excel: Application.Large(SomeRange,k) is all you need to specify.

I came in a little late to this thread. On re-reading the earlier posts I notice you were looping through the worksheets.

Code:
For Each ws In PA.Worksheets
    A = ws.Cells(Rows.Count, "A").End(xlUp).Row
    Do Until A = 2
        If Cells(A, "E").Value > Cells((A + 1), "E").Value And ..... Then

MARK858 made this comment in Post #6 :
I also say that I think you will probably hit more issues later in your code as you aren't qualifying your ranges with their worksheets.

I suspect your error is arising on the ActiveSheet, ie rather than the ws that you think you are testing. See how you're referring to Cells rather than ws.Cells? That means you're always referrring to Cells in the ActiveSheet. If you test ws.Name, then it will be correct as you loop through the worksheets, but you also need to refer to ws.Cells (and to similarly qualify any other .Range or similar reference where you want ws.Range rather than ActiveSheet.Range.

Rather than making multiple ws. references, you can also wrap in a With statement:
Code:
For Each ws In PA.Worksheets
    With ws
    A = .Cells(Rows.Count, "A").End(xlUp).Row
    Do Until A = 2
        If .Cells(A, "E").Value > Application.Large(.Cells(A - 10, "E").Resize(21), 2) Then
 
Last edited:
Upvote 0
I am receiving the End With without with error when I run the code with a with ws and end with around the If - Then line

Code:
With ws
[COLOR=#333333]If .Cells(A, "E").Value > Application.Large(.Cells(A - 10, "E").Resize(21), 2) Then
[/COLOR]End With

I also tried

Code:
If PA.ws.Cells(A, "E").Value > Application.Large(PA.ws.Cells((A - 10), "E").Resize(21), 2) Then

and received the "object doesn't support this property or method" error

Can you remind me how to check to test whether the cell contents are integer values or string values? They are all numbers, but may be stored as different data types as I understand it.
 
Upvote 0
I am receiving the End With without with error when I run the code with a with ws and end with around the If - Then line

Use the first construction. (Your loop defines ws as a worksheet in workbook PA. In your second construction, PA won't have a ws property).

The error message is a little misleading .... you just need to finish the If... Then .. Else statement, i.e.

Code:
With ws    
     If .Cells(A, "E").Value > Application.Large(.Cells(A - 10, "E").Resize(21), 2) Then
        'do stuff
    End If
End With

Can you remind me how to check to test whether the cell contents are integer values or string values? They are all numbers, but may be stored as different data types as I understand it.

I'm not clear what you're saying here. Numbers are numbers. They might be formatted and displayed differently, but they are still numbers. Text values are different e.g. '12345 is not the same as 12345, and formulae referencing this text cell probably won't behave the way you're expecting them to.

If you do have text values (which often occurs if you have imported data from another source) we could amend the VBA code to accommodate this possibility. But it would be better if you could fix the values in your Excel workbook, otherwise you may find there are other unintended consequences.
 
Upvote 0
Disregard the last question.

I got the conditional test working with the following, relatively simple fix

Code:
If ws.Cells(A, "E").Value > Application.Large(ws.Cells((A - 10), "E").Resize(21), 2) Then
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top