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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Can you describe what the "2" represents in the portion of the code?
Code:
[COLOR=#333333].Large(Cells(A - 10, "E").Resize(21), 2)[/COLOR]

Also, the resize function is resizing by row value?
 
Upvote 0
The Excel LARGE(array, k) function returns the kth largest value in the array. So if k = 2, we're asking for the second largest value.

If a cell's value is greater than the second largest value in a range, where that range includes the cell itself, then the cell must contain the unique maximum value, i.e. it's bigger than all the other cells.

Range.Resize(RowSize, ColumnSize) resizes the range to the specified RowSize and ColumnSize. If you omit either parameter, the row size or column size is left unchanged.

Cells(A-10,"E") has 1 row and 1 column, so .Resize(21) will resize this to 21 rows, 1 column.
 
Upvote 0
Thanks, I prefer this method,

I'm still receiving a type mismatch error on this line though

Could the "Application" object be creating this error?

Code:
If Cells(A, "E").Value > Application.Large(Cells((A - 10), "E").Resize(21), 2) Then
 
Upvote 0
I accidentally posted the same response twice, though I only intended to respond once.
 
Last edited:
Upvote 0
I'm still receiving a type mismatch error on this line though

... which takes us back to posts #1 and#2.

Check you don't have text values in the 21 cells in the range Cells(A - 10, "E") to Cells(A + 10, "E"). You may have cells that look like numbers but are actually text.

Also check that you don't have error values, e.g. #N/A, in any of these cells.

 
Upvote 0
I looked over the sheet and didn't find any text values or #N/A's. There are blank cells initially where the data begins. Could a format difference between cells with content and blank cells be critical here?
 
Upvote 0
Are you on the right worksheet?

When the code errors, what is the range being tested, i.e. Cells((A - 10), "E").Resize(21).Address ?

Are there at least two numeric values in this range? Or are the values perhaps all blank, or all but one blank? In which case the Large function will error.
 
Upvote 0
I added a few watches, including ws.Name and A

I think the ws is fine. The A value, at the time of the error, is the last row on the sheet with content in column "E". Ten cells above the A row value were occupied and ten below the A value were blank.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
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