VBA - Quick tweak to an old solved&closed thread

guiablo

New Member
Joined
Nov 30, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I was looking for some help to tweak the code posted by Trebor76 several years ago in this thread:

It is very close to what I am trying to accomplish now but there is something going on on line 21?
and I get a runtime error 13 type mismatch, which I imagine is because Trebor76's code is specifically looking for numeric values, whereas in search&match that I have, my table also contains non-numeric values (I guess I can call it strings).

A quick read of the thread above plus a screenshot of what I am trying to do, maybe helps the readers understand the task:

1669831122968.png

Any help would be appreciated!

Cheers,
G
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hopefully you won't mind if I take a stab at it without following the link (at least not at this time).
If you have mixed data types, declare the variable(s) as Variant - then it will accept virtually anything, including Null. If you need to do computations on variants, sometimes you have to bring conversion functions into play. It's safer than relying on M$ Office programs to correctly interpret your intent. Unfortunately, Excel seems to lack a built in function for handling null (Access does) so you'd have to create your own.
 
Upvote 0
You don't say what line 21 actually is.
Assuming it is the If-Countif line, try dropping the CLng conversion and make it just:
VBA Code:
        If Application.WorksheetFunction.CountIf(wsSrc.Range("A:A"), wsData.Range("A" & i)) > 0 Then
 
Upvote 0
Solution
Hello,
thanks for the replies, I tried both suggestions,
Micron, your suggestion gives back the same error 'type mismatch'; the only variables are row counts, which seems unrelated to the error;
Alex, your suggestion works perfectly!

Micron, if I try Alex suggestion and set the variables to Variant, it works too,

Cheers to both :)
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,913
Members
449,274
Latest member
mrcsbenson

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