Checking array for existing value

Asator

Board Regular
Joined
Apr 5, 2010
Messages
186
Trying to add only unique values to an array...

This worked:
Code:
               On Error Resume Next
                matcherr = wsf.Match(zsd17.Cells(iInv, 8).Value, invNums, 0)
                If Err.Number = 0 Then
                    invFound = True
                Else
                    invFound = False
                End If
                On Error GoTo 0

This did not:
Code:
                'check currently evalued line against array of unique invoices
                'For ckInvs = LBound(invNums, 1) To UBound(invNums, 1)
                '    If Val(invNums(ckInv)) = Val(zsd17.Cells(iInv, 8).Value) Then
                '        invFound = True
                '        Exit For
                '    End If
                'Next ckInvs

The question is, why? It seemed to add every value it found. I tried with and without the Val() operator. The data its reading from is stored as text, though its all numbers.

Any ideas? Obviously its working now, I'm just trying to figure out where I went wrong on the 2nd block of code.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Maybe the text-format is the culprit (not sure)

Try in the second code
If UCase(invNums(ckInv)) = UCase(zsd17.Cells(iInv, 8).Value) Then

M.
 
Upvote 0
Did you try the ugly and old debug-method?

Msgbox invNums(ckInv)
Msgbox zsd17.Cells(iInv, 8).Value

Just in case...

M.
 
Upvote 0
If you use

Option explicit

you will never have that problem again - seems you missed an S - I think

If Val(invNums(ckInvs))
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
rootytrip

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