选择一个范围,直到至少一列具有数值 [英] Selecting a range until at least one column has numeric value

查看:40
本文介绍了选择一个范围,直到至少一列具有数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,

我有一个包含数据的表:

I have a table with data:

    A       B       C
   Type   Height Length
    1       2       2
    2       3       9
    3       8       2
            2       3
    1               0
                    1

我一直在阅读如何选择该范围,但是我无法解决的问题是如何选择以上的范围,直到至少一列包含数值的行.但是问题在于范围是引用的一部分,并且Excel假定使用的行数较大,因为很多行都是空白并且是引用的一部分.

I've been reading how to select that range but the problem I can't solve is how to select the range above until the row where at least one column contains a numeric value. But the problem is that the range is a part of a reference and Excel assumes that the number of used rows is larger because a lot of rows are blank and are part of a reference.

所以我的问题是:

如何选择上述范围,直到第一行,其中A,B或C列均不包含至少一个数字条目,并且由于该范围是引用的一部分,因此使用的行数较大.

我尝试过

Sub Choose()
Dim Lastrow As Integer
Lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
MsgBox Lastrow
'Range("A2:C" & Lastrow).Select
End Sub

但是MsgBox返回118,这是因为我要选择的范围是引用的一部分...

But the MsgBox returns 118, which is because the Range I want to select is part of a reference...

有人有主意吗?

那行不通,仍然选择空单元格,因为它是引用...

That does not work, still select empty cells because it is reference...

Sub Sort3()
Dim oneRange As Range
Dim aCell As Range
Worksheets("Analys").Select
Set oneRange = ActiveCell.CurrentRegion.Range("D1")
Set aCell = Range("M10")

oneRange.Sort Key1:=aCell, Order1:=xlDescending, Header:=xlYes
End Sub

推荐答案

如果您有参差不齐"的列,例如:

If you have "ragged" columns like:

,并希望范围获取所有数据",然后:

and want a range to get "all the data", then:

Sub GetTheBlock()
    Range("A1").CurrentRegion.Select
End Sub

将选择 A1:C7

这篇关于选择一个范围,直到至少一列具有数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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