vba 选择一列中的所有空白单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25661659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:27:23  来源:igfitidea点击:

Select all blanks cells in a column

excelvba

提问by Kaiser

I have found below code to select next blank cell in a column. This code finds the next blank cell (data starting from A1). Suppose I have data from A1-A15 then a blank cell. This code does select A16 as it is next blank cell.

我发现下面的代码可以选择列中的下一个空白单元格。此代码查找下一个空白单元格(从 A1 开始的数据)。假设我有来自 A1-A15 的数据,然后是一个空白单元格。此代码确实选择了 A16,因为它是下一个空白单元格。

However I have more data below and I want to select all blank cells under each set of data. Please advise how to amend this code so that it can go through the whole of column A and select all next blank cells (If I make sense of what I have written). Thanks

但是我下面有更多数据,我想选择每组数据下的所有空白单元格。请告知如何修改此代码,以便它可以遍历整个 A 列并选择所有下一个空白单元格(如果我理解我所写的内容)。谢谢

Sub FindNextCell()
'Locate the next data entry cell in data entry column A
Dim FirstCell As String
Dim i As Integer
FirstCell = "A1"
Range(FirstCell).Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = "" Then
Exit Do
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

采纳答案by Kaiser

If you want to select all the blanks between the first and last cell you could use this

如果你想选择第一个和最后一个单元格之间的所有空白,你可以使用这个

Dim lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:A" & lr).SpecialCells(xlCellTypeBlanks).Select

Note: Avoid using .Select

注意:避免使用 .Select