无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【實(shí)例01-刪除多余空行】【 實(shí)例02-刪除多余空列】Excel表格VBA編程實(shí)例 代碼分享

2023-02-21 19:33 作者:凌霄百科_Excel辦公程序  | 我要投稿


實(shí)例01-刪除多余空行

Private Sub CommandButton處理_Click()

'判斷工作簿名,工作表名不為空

With ThisWorkbook.Worksheets("操作界面")

? ? ?If Trim(.Cells(2, "C").Value) = "" Or Trim(.Cells(6, "C").Value) = "" Then

? ? ?MsgBox "工作簿名稱和工作表名稱不能為空"

? ? ?Exit Sub

? ? ?End If


On Error GoTo 處理出錯(cuò)

'定義存儲工作簿工作表名稱變量

Dim wbname As String

Dim shname As String

wbname = Trim(.Cells(2, "C").Value)

shname = Trim(.Cells(6, "C").Value)

End With

'處理表格

With Workbooks(wbname).Worksheets(shname)

'獲得數(shù)據(jù)區(qū)域最大行列號

Dim rmax As Long

Dim cmax As Long

rmax = .UsedRange.Cells(.UsedRange.Count).Row

cmax = .UsedRange.Cells(.UsedRange.Count).Column

'循環(huán)判斷(反向)

Dim i, icmax

For i = rmax To 1 Step -1

? ? icmax = .Cells(i, cmax + 1).End(xlToLeft).Column

? ? If icmax = 1 And .Cells(i, 1) = "" Then? ? ?'滿足此條件為空行

? ? '刪除空行

? ? .Rows(i).Delete

? ? End If

Next i

End With

MsgBox "處理完成"

Workbooks(wbname).Worksheets(shname).Activate

Exit Sub

處理出錯(cuò):

MsgBox Err.Description

End Sub

實(shí)例02-刪除多余空列

Private Sub CommandButton處理_Click()

'判斷工作簿名,工作表名不為空

With ThisWorkbook.Worksheets("操作界面")

? ? ?If Trim(.Cells(2, "C").Value) = "" Or Trim(.Cells(6, "C").Value) = "" Then

? ? ?MsgBox "工作簿名稱和工作表名稱不能為空"

? ? ?Exit Sub

? ? ?End If


On Error GoTo 處理出錯(cuò)

'定義存儲工作簿工作表名稱變量

Dim wbname As String

Dim shname As String

wbname = Trim(.Cells(2, "C").Value)

shname = Trim(.Cells(6, "C").Value)

End With

'處理表格

With Workbooks(wbname).Worksheets(shname)

'獲得數(shù)據(jù)區(qū)域最大行列號

Dim rmax As Long

Dim cmax As Long

rmax = .UsedRange.Cells(.UsedRange.Count).Row

cmax = .UsedRange.Cells(.UsedRange.Count).Column

'循環(huán)判斷(反向)

Dim i, icmax

For i = cmax To 1 Step -1

? ? icmax = .Cells(rmax + 1, i).End(xlUp).Row

? ? If icmax = 1 And .Cells(1, i) = "" Then? ? '滿足此條件為空列

? ? '刪除空列

? ? .Columns(i).Delete

? ? End If

Next i

End With

MsgBox "處理完成"

Workbooks(wbname).Worksheets(shname).Activate

Exit Sub

處理出錯(cuò):

MsgBox Err.Description

End Sub


【實(shí)例01-刪除多余空行】【 實(shí)例02-刪除多余空列】Excel表格VBA編程實(shí)例 代碼分享的評論 (共 條)

分享到微博請遵守國家法律
奉新县| 浙江省| 栾城县| 永登县| 台东县| 祁东县| 玉林市| 北川| 香格里拉县| 鹿泉市| 余干县| 邹城市| 绵阳市| 合作市| 东丰县| 大冶市| 金湖县| 凉山| 高雄市| 万源市| 长汀县| 泽州县| 青浦区| 阿勒泰市| 樟树市| 平泉县| 织金县| 双城市| 黄陵县| 襄樊市| 塘沽区| 原阳县| 砀山县| 桐乡市| 乐至县| 旌德县| 大丰市| 丰原市| 静海县| 鹰潭市| 阳春市|