最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

實(shí)例19-間隔指定行數(shù)插入空行,實(shí)例20-提取多行多列 Excel表格VBA編程實(shí)例 代碼分享

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

實(shí)例19-間隔指定行數(shù)插入空行

Private Sub CommandButton處理_Click()

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

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

If Trim(.Cells(2, "C").Value) = "" Or Trim(.Cells(6, "C").Value) = "" Or Trim(.Cells(10, "C").Value) = "" _

Or Trim(.Cells(10, "D").Value) = "" Or Trim(.Cells(14, "C").Value) = "" Then

MsgBox "參數(shù)不能為空"

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)

Dim splitrow As Long

Dim startnum As Long

Dim stopnum As Long

splitrow = Trim(.Cells(14, "C").Value)

startnum = Trim(.Cells(10, "C").Value)

stopnum = Trim(.Cells(10, "D").Value)

End With

'處理表格

With Workbooks(wbname).Worksheets(shname)

Dim i

For i = stopnum To startnum Step splitrow * (-1)

.Rows(i).Insert

Next i

End With

Workbooks(wbname).Save

MsgBox "處理完成"

Workbooks(wbname).Activate

ActiveWindow.WindowState = xlMaximized

Workbooks(wbname).Worksheets(shname).Activate

Workbooks(wbname).Worksheets(shname).Cells(1, 1).Select

Exit Sub

處理出錯(cuò):

MsgBox Err.Description

End Sub


實(shí)例20-提取多行多列

Private Sub CommandButton提取列_Click()

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

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

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

MsgBox "參數(shù)不能為空"

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

'清除提取結(jié)果

With ThisWorkbook.Worksheets("提取結(jié)果")

.UsedRange.ClearFormats

.UsedRange.ClearContents

End With

'處理表格

With Workbooks(wbname).Worksheets(shname)

'循環(huán)

Dim i, icount

Dim imax As Long

imax = ThisWorkbook.Worksheets("提取行列號(hào)").Cells(1, 10000).End(xlToLeft).Column

icount = 1

For i = 1 To imax

If ThisWorkbook.Worksheets("提取行列號(hào)").Cells(1, i) <> "" Then

.Columns(CLng(ThisWorkbook.Worksheets("提取行列號(hào)").Cells(1, i))).Copy ThisWorkbook.Worksheets("提取結(jié)果").Columns(icount)

icount = icount + 1

End If

Next i

End With

MsgBox "處理完成"

ThisWorkbook.Worksheets("提取結(jié)果").Activate

Exit Sub

處理出錯(cuò):

MsgBox Err.Description

End Sub

Private Sub CommandButton提取行_Click()

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

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

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

MsgBox "參數(shù)不能為空"

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

'清除提取結(jié)果

With ThisWorkbook.Worksheets("提取結(jié)果")

.UsedRange.ClearFormats

.UsedRange.ClearContents

End With

'處理表格

With Workbooks(wbname).Worksheets(shname)

'循環(huán)

Dim i, icount

Dim imax As Long

imax = ThisWorkbook.Worksheets("提取行列號(hào)").Cells(1000000, 1).End(xlUp).Row

icount = 1

For i = 1 To imax

If ThisWorkbook.Worksheets("提取行列號(hào)").Cells(i, 1) <> "" Then

.Rows(CLng(ThisWorkbook.Worksheets("提取行列號(hào)").Cells(i, 1))).Copy ThisWorkbook.Worksheets("提取結(jié)果").Rows(icount)

icount = icount + 1

End If

Next i

End With

MsgBox "處理完成"

ThisWorkbook.Worksheets("提取結(jié)果").Activate

Exit Sub

處理出錯(cuò):

MsgBox Err.Description

End Sub


實(shí)例19-間隔指定行數(shù)插入空行,實(shí)例20-提取多行多列 Excel表格VBA編程實(shí)例 代碼分享的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
浦东新区| 中方县| 门源| 微山县| 肇源县| 安国市| 鄯善县| 临洮县| 鱼台县| 桃江县| 海阳市| 开平市| 兴山县| 名山县| 开化县| 屏东县| 灵寿县| 博野县| 浦东新区| 平昌县| 长宁区| 永平县| 广河县| 达尔| 深州市| 光泽县| 遂川县| 洛扎县| 杭锦旗| 塔城市| 新兴县| 民勤县| 防城港市| 滨州市| 岐山县| 乌恰县| 邛崃市| 榆林市| 靖安县| 浦县| 酒泉市|