Excel:选择所有行直到空单元格 [英] Excel: Selecting all rows until empty cell

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

问题描述

我要从两个相邻列中选择所有行,从头下方的行开始(这是固定的),并以第一行之前的行以空白单元结束。

I'd to select all rows from 2 adjacent columns, starting with the row below the header (this is fixed) and ending with the row before the first row with a blank cell.

鉴于以下示例...

    A       B
1   Item    Amount
2   Item1   1
3   Item2   4
4           2
5

我想选择范围A2:B3。第一行总是第2行,最后一行是第3行,因为它是第一行之前的一行有一个空白单元格。

I'd like to select the range A2:B3. The first row is always row 2, the last row is row 3 because it is the row before the first row with a blank cell.

我的目标是使用此选择在我完全填写当前最后一行之后的行中时自动对行进行排序和添加边框。在这个例子中,我必须填写A4,让行的一部分选择并应用上述的操作。

My goal is to use this selection to automatically sort and add borders to the rows after I've completely filled in the row below the current last row. In this example, I'd have to fill in A4 to make the row part of the selection and apply the aforementioned actions.

希望有人能帮助我..谢谢提前!

I hope anyone can help me.. Thanks in advance!

编辑

我已经提出了一个解决方案,基于chris neilsen的解决方案: / p>

I've come up with a solution, based on chris neilsen's solution:

Dim rng As Range
With Worksheets("YourSheet")
    Set rng1 = .Range(.Cells(2, 1), .Cells(2, 2).End(xlDown))
    Set rng2 = .Range(.Cells(2, 2), .Cells(2, 1).End(xlDown))
    Set r = Application.Intersect(rng1, rng2)

End With


推荐答案

尝试这个

Dim rng as Range
With Worksheets("YourSheet")
    Set rng = .Range(.Cells(1,2), .Cells(1,2).End(xlDown)).Resize(,2)
End With

变量 rng 现在将设置为 A2:B3

这篇关于Excel:选择所有行直到空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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