0% found this document useful (0 votes)
183 views1 page

Excel VBA Type Mismatch Error Passing Range To Array - Stack Overflow

Uploaded by

vaskore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
183 views1 page

Excel VBA Type Mismatch Error Passing Range To Array - Stack Overflow

Uploaded by

vaskore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

Products Search… 1 1

Home
Excel VBA Type Mismatch Error passing range to array Ask Question

PUBLIC Asked 6 years, 7 months ago Active 6 years, 7 months ago Viewed 16k times

Questions
I'm trying to retrieve the values of an array of cells in a worksheet (stored as an array rather than
Tags The Overflow Blog
simple cells), but for some reason keep getting a Run-Time Error 13 Type Mismatch. I've read
Users 2 posts about similar issues, but many of those seem to have to do with either the array being of the Introducing The Key
wrong type (ie NOT Variant type), or being of static size.
FIND A JOB Podcast 326: What does being a “nerd”
even mean these days?
Jobs Here is the relevant line where the error occurs in debugging:

Companies Featured on Meta


Dim SizeSelection() As Variant
TEAMS SizeSelection = Workbooks("Wheels.xlsx").Worksheets("Test").Range("B1:W1")
Stack Overflow for Teams is now free for
up to 50 users, forever
Stack Overflow for
Teams – Collaborate I've also tried using Announcing “The Key™” - copy paste like
and share knowledge you've never done before
with a private group.
Dim SizeSelection() As Variant
SizeSelection = Array(Workbooks("Wheels.xlsx").Worksheets("Test").Range("B1:W1")) Linked

26 Why am I having issues assigning a Range


but still get the same error. Other than the 2 common mistakes mentioned above, does anyone
to an Array of Variants
have any idea why i would be getting a type mismatch? I've tried removing the array and storing
the values in regular cells, but that made no difference. 0 Pass ListObject to array. type variable
String error
Create a free Team
Oh, I should mention that the data I'm trying to retrieve is in another workbook (though that should
Related
What is Teams? be clear from the code above) and that workbook is already open.
560 How to avoid using Select in Excel VBA
Thanks! Mike
2 range type mismatch vba
arrays excel vba type-mismatch
1 Type Mismatch VBA when copying range
data to array
Share Edit Follow asked Aug 11 '14 at 1:14 3 Excel VBA Run-time error '13': Type
MikeG mismatch, when passing a Variant Array to
21 1 1 2 Application.Index method

0 Excel VBA: Type Mismatch

3 This is a good read and in fact answers your question. – L42 Aug 11 '14 at 6:26 0 Type Mismatch assigning worksheets to
array
Add a comment
0 Type-Mismatch on For Each Range

1 Answer Active Oldest Votes


Hot Network Questions
Meaning of "she had wept over the reservation."
Change Dim SizeSelection() As Variant to Dim SizeSelection As Variant and you should
What will it take to get 1,000,000 people living in
be ok.
space habitats?
9 Are bike repair shops adverse to changing
Share Edit Follow answered Aug 11 '14 at 1:47 chainsets?
stobin Why does UV radiation from the Sun cause skin
1,008 8 8 cancer?

Anti Arzela-Ascoli
1 I should also admit that I don't actually know why using the parenthesis will cause an error in this situation,
Is "mens semita tua" the correct translation for
especially since Dim Arr() As Variant: Arr = Range("A1:C5") is acceptable but Dim "mind your path"?
Arr() As Variant: Arr = ThisWorkbook.Sheets(1).Range("A1:C5") isn't. I only know
from encountering it myself. – stobin Aug 11 '14 at 2:12 Recommendations on how to buy clipless bike
shoes
1 Hi, you might be interested in the link I posted in the OP's question. That in fact answers his and your
Temperature sensor read out is influenced by LED
question. – L42 Aug 11 '14 at 6:37
Red Herring Redherring
Thanks for the quick responses! For some reason declaring the variable without parentheses didn't work,
but declaring a range variable and setting SizeSelection equal to that did the trick. @L42 thanks for the Getting buy-in for clean code and refactoring
link to the article, I hadn't come across that one in my searching. To be honest I don't fully understand the
reasoning behind it, but at least now I know the workaround if I encounter this again! Thanks so much for Red Black Trees for Limit Order Book
saving my sanity! – MikeG Aug 12 '14 at 3:31
Can I glue the X axis to the Y axis?
@MikeG It's pretty simple. You just need to explicitly instruct excel what you're passing to an array of
variant variable especially if what you're passing could be one of two things. – L42 Aug 12 '14 at 4:26 more hot questions

Add a comment Question feed

Your Answer

Links Images Styling/Headers Lists Blockquotes Code HTML Tables Advanced help

Post Your Answer

Not the answer you're looking for? Browse other questions tagged arrays excel vba type-mismatch

or ask your own question.

STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn Instagram
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Advertising Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Terms of Service
Disable Responsiveness Contact Us
Cookie Settings
site design / logo © 2021 Stack Exchange Inc; user contributions
Cookie Policy licensed under cc by-sa. rev 2021.4.1.38970

You might also like