VBA中这串代码什么意思,逐句祥细解释
Sub按钮1_Click()Columns("K:M").SelectSelection.ClearContentsJ=Cells(Rows.Count,1).End(3...
Sub 按钮1_Click()
Columns("K:M").Select
Selection.ClearContents
J = Cells(Rows.Count, 1).End(3).Row
k = 2
For I = 3 To J
Range("B2:J2").Select
Selection.Copy
Cells(k, 12).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Cells(I, 2).Select
Application.CutCopyMode = False
Selection.Copy
Range(Cells(k, 11), Cells(k + 7, 11)).Select
ActiveSheet.Paste
Range(Cells(I, 2), Cells(I, 9)).Select
Application.CutCopyMode = False
Selection.Copy
Cells(k, 13).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
k = k + 8
Next
J = Cells(Rows.Count, 11).End(3).Row
For I = J To 1 Step -1
If Cells(I, 13) = "" Then
Range(Cells(I, 11), Cells(I, 13)).Select
Selection.Delete Shift:=xlUp
End If
Next
Range("K1").Select
End Sub 展开
Columns("K:M").Select
Selection.ClearContents
J = Cells(Rows.Count, 1).End(3).Row
k = 2
For I = 3 To J
Range("B2:J2").Select
Selection.Copy
Cells(k, 12).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Cells(I, 2).Select
Application.CutCopyMode = False
Selection.Copy
Range(Cells(k, 11), Cells(k + 7, 11)).Select
ActiveSheet.Paste
Range(Cells(I, 2), Cells(I, 9)).Select
Application.CutCopyMode = False
Selection.Copy
Cells(k, 13).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
k = k + 8
Next
J = Cells(Rows.Count, 11).End(3).Row
For I = J To 1 Step -1
If Cells(I, 13) = "" Then
Range(Cells(I, 11), Cells(I, 13)).Select
Selection.Delete Shift:=xlUp
End If
Next
Range("K1").Select
End Sub 展开
2个回答
展开全部
你这程序的表格与我发给你的下移了一行吗?你改时注意单元格的描述是CELLS(行,列),你有的改了,有的未改。最好你将真实表格发给我。原程序说明:
Sub 按钮1_Click() '本程序 处理A:I列的数据,行数可多行
Columns("K:M").Select '选择你要放结果 的K:M列
Selection.ClearContents '清空
j = Cells(Rows.Count, 1).End(3).Row '看A列有多少行
k = 1 '结果 从K列的第一行开始放
For i = 2 To j '取内容从A:I列的数据的第二行开始,到最后j行
Range("B1:I1").Select '选择标题行内容
Selection.Copy '复制
Cells(k, 12).Select '选择粘贴结果位置
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True '粘贴到结果区
Cells(i, 1).Select '选择A列的名称
Application.CutCopyMode = False '复制
Selection.Copy '
Range(Cells(k, 11), Cells(k + 7, 11)).Select '选择要粘贴名称的区域
ActiveSheet.Paste '粘贴
Range(Cells(i, 2), Cells(i, 9)).Select '选择B:I区域的路径
Application.CutCopyMode = False '
Selection.Copy '复制
Cells(k, 13).Select '选择路径的粘贴结果位置
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True '粘贴到结果区
k = k + 8 '结果区域下移8行
Next '处理下一个,至将A:I列的数据全部粘贴到K:M结果区域
j = Cells(Rows.Count, 11).End(3).Row '看K列有多少行
For i = j To 1 Step -1 '从K列最后一行开始往上检查
If Cells(i, 13) = "" Then '假如M列上的内容是空的,则
Range(Cells(i, 11), Cells(i, 13)).Select '是就选择该行K:M内容
Selection.Delete Shift:=xlUp '删除
End If '结束假如
Next '上一行
Range("K1").Select '选择结果的首单元格
End Sub
看看我的程序是否达到你的要求?如有不清楚的请再问我。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询