得到实际的使用范围 [英] Getting the actual usedrange

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

问题描述

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



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



有没有办法只能获得包含数据的实际使用范围?

解决方案

什么样的按钮,表单控件和ActiveX控件都不应该影响使用范围。



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

  Sub ResetUsedRng()
Application.ActiveSheet.UsedRange
End Sub

如果没有,可能会有一些格式化挂起。尝试清除/删除最后一行后的所有单元格。



关于上述内容,请参阅:



Excel开发人员提示



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

  Dim rLastCell As Range 

设置rLastCell = ActiveSheet.Cells.Find(What:=*,After:=。Cells(1,1),LookIn:= xlFormulas,LookAt:= _
xlPart,SearchOrder:= xlByRows,SearchDirection = xl上一个,MatchCase:= False)

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

I have a Excel worksheet that has a button.

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?

解决方案

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

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 Developer Tip

Another method to find the last used cell:

    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天全站免登陆