How to bypass 'Index was outside the bounds of the array'

Hi,

Currently, I am looking a value in another excel sheet and get the beside column value

Code:

myd.Select(“[Staff ID] =‘" + a3+"’”)(0)(1).ToString

I tried to use If to by pass this code if no match is found. However, the if is giving an error still:
If: Index was outside the bounds of the array.

myd.Select(“[Staff ID] =‘" + a3+"’”)(0)(1).ToString.Length > 0

How to bypass the code?

Thank you xoxo

If there is no match, the output of DataTable.Select contains no rows. So you are trying to access the empty row that’s why you are getting the error.

Follow this -

Assign, rows = myd.Select(“[Staff ID] =’" + a3 + "’”)

If rows.Count > 0 then
take the value from the next column, rows(0)(1)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.