Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

fixing mismatch error

0

hi professional,

I  need  some  help  to  fix  this  error  . I  put  the  right  result  in sheets(report,import,export)   . the  code  combine  data  based on  column B  for  each  sheet  separately  with  calculate  average  price  . the  error occures in column PRICE  (G) in this  line 

 a(dic(a(i, 2)), 7) = a(dic(a(i, 2)), UBound(a, 2) - 1) / a(dic(a(i, 2)), UBound(a, 2))
.it shows mismatch 

I  hope  finding way  to  fix  this  problem.

Answer
Discuss

Answers

0
Selected Answer

Kalil

I ran your sub test() in the uploaded file but did not get a "type mismatch" error. If the entries in columns H and I are numeric, it should work (provided you populate the arrays correctly, which you seem to).

If however you type "S23.00" in a cell in column I say, that line will cause a "type mismatch" error. That said, the total in column J would show a #VALUE error so should be obvious (unless a value is typed there too)..

I haven't checked your average price calcalations- I leave that to you.

Discuss

Discussion

Hi John  , 
you're  right  about  this If however you type "S23.00" in a cell in column I say, that line will cause a "type mismatch" error.
good spotting ! 
thanks  very  much  for  your  help
Kalil (rep: 36) Oct 16, '21 at 7:20 am
Glad that helped Kalil.

Perhaps you should use Data Validation on those columns to limit the entries to numbers only. Alternatively VBA's Isnumeric method could be used to test values.
John_Ru (rep: 6142) Oct 16, '21 at 7:35 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login