在Excel中我想删除所有空单元格,以便所有行和列都有文本。
cell1 cell2 cell3
1 peter
...
所以,我想这样:
cell1 cell2
1 peter
如何删除空单元格?
我使用ods格式,是否相关?
答案 0 :(得分:0)
尝试以下解决方案
1.在Excel中选择范围
2.按[F5]。
3.在生成的“转到”对话框中
4.单击特殊。单击“空白”选项,然后单击“确定”。
5.这样选择所选范围内的空白单元格(您可能认为是行)。
6.右键单击>删除>选择所需的选项(Moveup,... left ..)
重复上述步骤,直至达到预期的效果
来源:http://www.techrepublic.com/blog/microsoft-office/a-quick-way-to-delete-blank-rows-in-excel/
答案 1 :(得分:0)
在您的具体示例中,您可以执行F5(转到) - >特别.. - >空白 - >好。这将选择空白单元格 - 然后您可以右键单击 - >删除 - >将细胞移开。我对你桌子的结构不确定,所以这可能会弄乱其他东西吗?
答案 2 :(得分:0)
如果你想拥有一个VBA功能为你做,那么你将需要像:
Sub ClearBlanks(sheet As Worksheet)
Dim rng As Range
Dim firstRow As Integer
Dim firstCol As Integer
Dim lastRow As Integer
Dim lastCol As Integer
Dim i As Integer
Dim j As Integer
Dim isEmpty As Boolean
Set rng = sheet.UsedRange
firstRow = rng.Item(1).row
firstCol = rng.Item(1).Column
lastRow = firstRow + rng.Rows.Count - 1
lastCol = firstCol + rng.Columns.Count - 1
For i = lastCol To firstCol Step -1
isEmpty = True
For j = firstRow To lastRow
If sheet.Cells(j, i).Value <> "" Then
isEmpty = False
Exit For
End If
Next
If isEmpty Then
sheet.Columns(i).Delete
End If
Next
For j = lastRow To firstRow Step -1
isEmpty = True
For i = firstCol To lastCol
If sheet.Cells(j, i).Value <> "" Then
isEmpty = False
Exit For
End If
Next
If isEmpty Then
sheet.Rows(j).Delete
End If
Next
For i = firstCol - 1 To 1 Step -1
sheet.Columns(i).Delete
Next
For i = firstRow - 1 To 1 Step -1
sheet.Rows(i).Delete
Next
End Sub
请注意,这只会删除完全为空的列或行,因此如果行或列中的某些单元格为空,则会保留表结构。