选择带有空格的列中的最后一个单元格 [英] Select last cell in a column with blanks

查看:41
本文介绍了选择带有空格的列中的最后一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用 VBA 中的数据填充的列中查找最后一个单元格.问题是,在该范围内,有空白单元格.如果有空格,有没有办法选择带有数据的最后一个单元格?任何帮助将不胜感激!我在下面粘贴了我的范围定义.

I am trying to find the last cell in a column that is populated with data in VBA. The problem is, in the range, there are blank cells. Is there any way to select the last cell with data if there are blanks? Any help would be greatly appreciated! I have pasted my range definitions below.

If Range("BL2") <> "" Or Range("BM2") <> "" Then
                            Set usr11 = Range("BL:BL")
                            Set usr12 = Range("BM:BM")

推荐答案

使用查找

这将适用于 ActiveSheet

This will work on the ActiveSheet

Dim lngLastRow as Long

'If column is A
lngLastRow = Columns(1).Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

这篇关于选择带有空格的列中的最后一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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