【发布时间】:2012-09-28 12:02:59
【问题描述】:
使用下面的代码,我试图推断存在已定义值的列右侧的列字母。例如,如果 D1 = 'Postcode',我希望 insert_col 等于 'E'。
如果title_range 中存在值“Postcode”,则此方法有效,但如果不存在,我会在最后一行出现错误(类型不匹配)。
根据 Match 的文档,如果查找值不存在于 renge 中,则返回 Excel 错误“N/A”,但检查 xlErrNA 以退出函数不起作用。
' 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)
有没有人知道我做错了什么?谢谢。
【问题讨论】:
-
感谢您的提示,
If IsError() Then检查帮助了我。
标签: excel error-handling excel-2007 vba