我在编写读取空行(间隙)的代码时遇到困难,并从列C
读取填充(标题)行,但只删除带有标题的空行,而不是空行(间隙)。
如果可以创建代码来读取列C
以获取行标题和空白间隙;或者只是列C
中没有任何标题的间隙。然后,如果列D
中标题为空的行直到L
而n/m
表示没有任何意味着它为空,则应该删除该行但不删除空白。此图显示了文件的格式,需要删除第四行。任何帮助将不胜感激
我的代码带有一些绒面革代码。我有点困惑,我会怎么做...
Dim WS As Worksheet
For Each WS In Sheets
WS.Activate
Dim n As Long
Dim nlast As Long
Dim rw As Range
Set rw = ActiveWorkbook.ActiveSheet.UsedRange
nlast = rw.count
For n = nlast To 9 Step -1
If (rw.Cells(n, 3).Value = "") Then
keep
ElseIf (rw.Cells(n, 3).Value = text) Then
keep but
Else (rw.Cells(n, 4).Value = "" And rw.Cells(n, 5).Value = "" And rw.Cells(n, 6).Value = "" And rw.Cells(n, 7).Value = "" And rw.Cells(n, 8).Value = "" And rw.Cells(n, 9).Value = "" And rw.Cells(n, 10).Value = "" And rw.Cells(n, 11).Value = "") Then
rw.Rows(n).Delete
End If
Next n
Next WS
End Sub
答案 0 :(得分:1)
你非常接近。这是固定代码:
Sub Test()
Dim WS As Worksheet
Dim n As Long
Dim nlast As Long
For Each WS In Sheets
nlast = WS.UsedRange.Rows(WS.UsedRange.Rows.Count).Row
For n = nlast To 9 Step -1
If WS.Cells(n, 3).Value <> "" And WS.Cells(n, 4).Value = "" And WS.Cells(n, 5).Value = "" And _
WS.Cells(n, 6).Value = "" And WS.Cells(n, 7).Value = "" And WS.Cells(n, 8).Value = "" And _
WS.Cells(n, 9).Value = "" And WS.Cells(n, 10).Value = "" And WS.Cells(n, 11).Value = "" Then
WS.Rows(n).EntireRow.Delete
End If
Next n
Next WS
End Sub