[英]Remove empty cells in Excel
在Excel中,我想删除所有空单元格,以便所有行和列都具有文本。
cell1 cell2 cell3
1 peter
...
所以,我想要这样:
cell1 cell2
1 peter
如何删除空单元格?
我使用ods格式,这相关吗?
尝试以下解决方案
1.在Excel中选择范围
2.按[F5]。
3.在出现的“转到”对话框中
4.单击特殊。 单击空白选项,然后单击确定。
5.这样做会在选定范围内选择空白单元格(您可能会认为是行)。
6.右键单击>删除>选择所需的选项(移动,...向左..)
重复上述步骤,直到达到理想的产量
资料来源: http : //www.techrepublic.com/blog/microsoft-office/a-quick-way-to-delete-blank-rows-in-excel/
在您的特定示例中,您可以执行F5(转到)->特殊。->空白->确定。 这将选择空白单元格-然后您可以右键单击->删除->向左移动单元格。 我不确定您的表格结构,因此这可能会使其他事情搞砸了吗?
如果您想拥有一个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
请注意,这只会删除完全为空的列或行,因此,如果仅行或列中的某些单元格为空,则将保留表结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.