使用匹配以测试范围是否具有任何内容

问题描述 投票:0回答:1
I一排具有一系列单元格,并希望测试它们是否没有内容。 从数据库中,我找到了以下解决方案来解决我的问题。

如果不是iserror(application.match(valuetosearchfor,rangetosearchin,0))然后

我将范围固定为更像我的需要 If Not IsError(Application.Match("", rRng.Offset(lOffset).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)), 0)) Then

它没有跳入我的有条件的陈述,我尝试了对面

If Not IsError(Application.Match("<>", rRng.Offset(lOffset).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)), 0)) Then

因为它没有达到我的条件声明。 其他人必须引起问题,但我不知道在哪里寻找或寻找什么。刚刚找到了一本食谱说明:-)。 首先检查一个范围真的存在

rRng.Offset(lCorrection).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)).Select

选择正确的范围。 我相信条件“”或“ <>”是正确的输入,它比在单元格中提出的简单……循环又有什么我想念的东西。 有没有人知道有什么问题? 预先感谢

如果您愿意使用匹配以外的其他东西,那么以下将测试一行定义的范围是否为空白;它使用CountBlank,然后将结果与定义范围内的单元格数进行比较。

Sub IsRangeEmpty() '''define the range Dim rRng As Range '''I'm using Rows(18) only in my testing data...you'll probably need to change this reference Set rRng = Rows(18).Cells If Application.Evaluate("=COUNTBLANK(" & rRng.Offset(lOffset).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)).Address & ")") = rRng.Cells.Count Then Debug.Print "Empty Row" & vbTab & rRng.Offset(lOffset).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)).Address Else Debug.Print "Some cells are not empty" End If End Sub

excel vba match
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.