Using the code below, I am trying to extrapolate the column letter of to the right of a column where a defined value exists. For example, if D1 = ‘Postcode’, I want insert_col to equal ‘E’.
This works if the value ‘Postcoade’ exists in title_range, but if it does not I get an error on the last line (Type mismatch).
According to the docs for Match, if the lookup value does not exist in the reange, the Excel error “N/A” is returned, but checking for xlErrNA to exit the function does not work.
' Work out the column to insert
insert_col_pos = Application.Match("Postcode", title_range, 0)
If insert_col_pos = xlErrNA Then Exit Function ' Exit if the column to insert next to does not exist
insert_col = GetInsertCol(insert_col_pos + 1)
Does any body know what I am doing wrong? Thanks.
What you want is
Provided that
insert_col_posisDim‘ed asVariant