excel能翻译中文吗
584
2022-12-03
Excel用VBA删除空行和空列
在Excel中删除空行和空列的方法有很多,下面的方法是用VBA代码来删除工作表指定区域中的空行和空列:
Option Explicit
Sub Delete_Empty_Rows()Dim rnArea As RangeDim lnLastRow As Long, i As Long, j As Long
Application.ScreenUpdating = FalselnLastRow = Selection.Rows.CountSet rnArea = Selection
j = 0
For i = lnLastRow To 1 Step -1If Application.CountA(rnArea.Rows(i)) = 0 ThenrnArea.Rows(i).Deletej = j + 1End IfNext i
rnArea.Resize(lnLastRow – j).Select
Application.ScreenUpdating = TrueEnd Sub
Sub Delete_Empty_Columns()Dim lnLastColumn As Long, i As Long, j As LongDim rnArea As Range
Application.ScreenUpdating = FalselnLastColumn = Selection.Columns.CountSet rnArea = Selection
j = 0
For i = lnLastColumn To 1 Step -1If Application.CountA(rnArea.Columns(i)) = 0 ThenrnArea.Columns(i).Deletej = j + 1End IfNext i
rnArea.Resize(, lnLastColumn – j).Select
Application.ScreenUpdating = FalseEnd Sub
在运行代码前,先选择需要删除空行和空列的区域。如果要删除空行,则运行Delete_Empty_Rows(),指定区域中的空行将被删除。注意所谓空行是在指定区域中的,如果在指定区域内是空行,而在指定区域外不是空行,那么这些空行还是将会被删除。删除空列则运行Delete_Empty_Columns()。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。