【发布时间】:2015-08-08 08:34:58
【问题描述】:
我的垂直数据在 B:G 列中有间隙
我希望我的代码执行以下操作:
- B 列的屏幕
- 找到一个空单元格
- 删除空单元格的整行
- 重复这个直到找到 10 个空单元格(这是最棘手的,因为它不应该删除这 10 个空单元格)//10 只是一个没有更多数据的任意数字
- 然后转到 C 列,重复整个过程,依此类推,直到筛选完所有列
我有一些基本的 VBA 知识,这是迄今为止我在该主题上找到的代码,但是我脑子里一团糟如何处理这个问题。
我遇到的主要问题是代码如何知道何时停止删除并移至下一列。
下面的代码在 B 列中找到下一个空单元格并选择它。
Public Sub SelectFirstBlankCell()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 6 'column F has a value of 6
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
Exit For 'This is missing...
End If
Next
End Sub
【问题讨论】: