【发布时间】:2011-01-05 12:58:34
【问题描述】:
我是 Experts-Exchange 的新用户,因为我注意到他们提高了“免费高级服务”积分门槛。
在包含 Excel“列表”的工作表中使用 End(xlup) 命令时,Excel 2003 似乎存在问题。如果我选择在“列表”边界之外的单元格 ,然后尝试使用 VBA 选择工作表中的最后一个单元格,我必须调用 .Select 函数两次以确保获得正确的单元格。如果原始单元格在“列表”边界内,那么我只需要一个.Select。我的破解解决方案如下,有两个选择,因为我永远无法确定保存时可以选择哪个单元格。我在打开时包含版本检查以在 Excel 2007 中运行不同的代码(此代码在 2007 年失败,其中 .End(xlUp) 命令正常工作)。
有没有更雄辩的方法来处理这个问题? 感谢您的帮助!
.Range("A1").Select
.Cells(.Rows.Count, "A").End(xlUp).Select
.Cells(.Rows.Count, "A").End(xlUp).Select
'two .Selects needed to select correct cell in Excel 2003 list because original selection (A1) was not in list'
.Range("A1").Select
.Cells(.Rows.Count, "T").End(xlUp)(-2, 1).Select
.Cells(.Rows.Count, "T").End(xlUp)(-2, 1).Select
'two .Selects needed to select correct cell in Excel 2003 list because original selection (A1) was not in list'
.Cells(.Rows.Count, "T").End(xlUp)(-3, 1).Select
'only one select needed here because original selection above was within the list'
【问题讨论】: