获取实际使用范围 [英] Getting the actual usedrange

查看:37
本文介绍了获取实际使用范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的 Excel 工作表.

I have a Excel worksheet that has a button.

当我调用 usedRange() 函数时,它返回的范围包括按钮部分.

When I call the usedRange() function, the range it returns includes the button part.

无论如何我可以得到包含数据的实际使用范围吗?

Is there anyway I can just get actual used range that contains data?

推荐答案

什么样的按钮,无论是 Forms 控件还是 ActiveX 控件都不应该影响使用范围.

What sort of button, neither a Forms Control nor an ActiveX control should affect the used range.

excel 不能很好地跟踪使用范围是一个已知问题.通过 VBA 对使用范围的任何引用都会将该值重置为当前使用的范围.所以尝试运行这个子过程:

It is a known problem that excel does not keep track of the used range very well. Any reference to the used range via VBA will reset the value to the current used range. So try running this sub procedure:

Sub ResetUsedRng()
    Application.ActiveSheet.UsedRange 
End Sub 

如果不知道您可能有一些格式悬而​​未决.尝试清除/删除最后一行之后的所有单元格.

Failing that you may well have some formatting hanging round. Try clearing/deleting all the cells after your last row.

关于以上内容,请参见:

Regarding the above also see:

Excel 开发者提示

另一种找到最后使用的单元格的方法:

    Dim rLastCell As Range

    Set rLastCell = ActiveSheet.Cells.Find(What:="*", After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)

更改搜索方向以查找第一个使用的单元格.

Change the search direction to find the first used cell.

这篇关于获取实际使用范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆