VBA runtime error 13 - Type Mismatch

karan2807

New Member
Joined
Jan 5, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi Team ,

I need to get the whole row value from a 2d array but I am getting the runtime error 13 - Type Mismatch error.

I am using the following expression.

arr1 = Application.WorksheetFunction.Index(SparepartData, 1, 0)

sparepartdata = Array.



Please help
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi & welcome to MrExcel.
If SparepartData is a 2d array & arr1 is a variant, then this line should work
VBA Code:
arr1 = Application.WorksheetFunction.Index(SparepartData, 1, 0)
If you are having problems, then please post the rest of the code using code tags
 
Upvote 0
Hi & welcome to MrExcel.
If SparepartData is a 2d array & arr1 is a variant, then this line should work
VBA Code:
arr1 = Application.WorksheetFunction.Index(SparepartData, 1, 0)
If you are having problems, then please post the rest of the code using code tags
Hi , Yes they are the same as you mentioned still I am getting a same error dont know why? Can you help me in that
 
Upvote 0
Not unless you do what I asked. ;)
1641410269456.png
 
Upvote 0
I asked you to post your code, not show an image of the array.
 
Upvote 0
I asked you to post your code, not show an image of the array.
VBA Code:
Private function ProcessInvoice()

SparepartData = GetSparepartData(StrUniInvoiceNo(datarow))
 
 SparepartDatarow = Application.WorksheetFunction.Index(SparepartData, 1, 0)
 
End Function


Private Function GetSparepartData(StrInvoiceNumber)

Application.ScreenUpdating = False

Application.Calculation = xlCalculateManual

Application.EnableEvents = False

'Set objRecordSet = RunSQL("C:\Users\karora3\OneDrive - Deloitte (O365D)\Documents\BMW Germany\Docs\test1.xlsx", "Select [BUNO],[RECHNR],[RECHDAT],[AUF_ART],[SELBZAHLER],[TYP_KEY],[BAUREIHE],[ERSTZULASSUNG],[AW_NUMMER],[AW_MENGE],[TEILENUMMER],[TEILE_MENGE],[STORNO],[STORNO_TXT],0,[RABATT] from [CalculationSheet$] where [RECHNR] ='" & StrInvoiceNumber & "' AND [TEILENUMMER] Is Not Null")

Set objRecordSet = RunSQL("C:\Users\karora3\OneDrive - Deloitte (O365D)\Documents\BMW Germany\Docs\test1.xlsx", "Select [BUNO],[RECHNR],[AUF_ART]from [CalculationSheet$] where [RECHNR] ='" & StrInvoiceNumber & "' AND [TEILENUMMER] Is Not Null")


SparepartTableArr = RecordsetToArray(objRecordSet)

Set objRecordSet = Nothing

Application.ScreenUpdating = True

Application.Calculation = xlCalculateAutomatic

Application.EnableEvents = True

GetSparepartData = SparepartTableArr


End Function


In first function and I am calling the second function which gives me the array in the sparepartdata then I am using the expression
SparepartDatarow = Application.WorksheetFunction.Index(SparepartData, 1, 0)
, which is giving me the error
 
Last edited by a moderator:
Upvote 0
Thanks for posting the code, unfortunately there is no way of testing it at this end so I cannot tell why you are getting the error.
 
Upvote 0
One reall
VBA Code:
Private function ProcessInvoice()

SparepartData = GetSparepartData(StrUniInvoiceNo(datarow))
 
 SparepartDatarow = Application.WorksheetFunction.Index(SparepartData, 1, 0)
 
End Function


Private Function GetSparepartData(StrInvoiceNumber)

Application.ScreenUpdating = False

Application.Calculation = xlCalculateManual

Application.EnableEvents = False

'Set objRecordSet = RunSQL("C:\Users\karora3\OneDrive - Deloitte (O365D)\Documents\BMW Germany\Docs\test1.xlsx", "Select [BUNO],[RECHNR],[RECHDAT],[AUF_ART],[SELBZAHLER],[TYP_KEY],[BAUREIHE],[ERSTZULASSUNG],[AW_NUMMER],[AW_MENGE],[TEILENUMMER],[TEILE_MENGE],[STORNO],[STORNO_TXT],0,[RABATT] from [CalculationSheet$] where [RECHNR] ='" & StrInvoiceNumber & "' AND [TEILENUMMER] Is Not Null")

Set objRecordSet = RunSQL("C:\Users\karora3\OneDrive - Deloitte (O365D)\Documents\BMW Germany\Docs\test1.xlsx", "Select [BUNO],[RECHNR],[AUF_ART]from [CalculationSheet$] where [RECHNR] ='" & StrInvoiceNumber & "' AND [TEILENUMMER] Is Not Null")


SparepartTableArr = RecordsetToArray(objRecordSet)

Set objRecordSet = Nothing

Application.ScreenUpdating = True

Application.Calculation = xlCalculateAutomatic

Application.EnableEvents = True

GetSparepartData = SparepartTableArr


End Function


In first function and I am calling the second function which gives me the array in the sparepartdata then I am using the expression
SparepartDatarow = Application.WorksheetFunction.Index(SparepartData, 1, 0)
, which is giving me the error. Also one strange thing that I have noticed -my 2d array has 15 columns but If I am having only 3 columns in an array it is working fine.
 
Upvote 0

Forum statistics

Threads
1,214,537
Messages
6,120,096
Members
448,944
Latest member
SarahSomethingExcel100

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