excel的vb中单击命令按钮把sheet1中的A列内容复制到sheet6中A列

 我来答
鱼木混猪哟
高粉答主

2016-04-20 · 专注Office,尤其Excel和VBA
鱼木混猪哟
采纳数:6078 获赞数:33697

向TA提问 私信TA
展开全部

软件版本:Office2010

方法如下:

1.开发工具,插入,按钮:

2.按下鼠标,拖动,并放开,在新弹框中点击新建:

3.输入如下代码:

4.返回Excel,点击按钮1:

5.Sheet6中A1的内容,就等于Sheet1中A1的内容了:

匿名用户
2016-04-18
展开全部
程序如下,希望你喜欢:
Sub Run_Sort_Copy()
On Error GoTo ErrExit
Dim strSheetName_1 As String, strSheetName_2 As String
Dim iClass As Long, iMaxRow As Long, iRow As Long, iNewRow As Long
Application.ScreenUpdating = False
strSheetName_1 = "Sheet1" '此处可修改表1名称
strSheetName_2 = "Sheet2" '此处可修改表2名称
Sheets(strSheetName_1).Select
Range("A1").CurrentRegion.Select
iMaxRow = Selection.Rows.Count
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range( _
"C2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin, DataOption1:= _
xlSortNormal, DataOption2:=xlSortNormal

iRow = 2
iClass = Range("B2").Value
iNewRow = 1
GoSub CopyMain
GoSub CopyRange

iRow = 3
Do Until iRow > iMaxRow
If Range("B" & iRow).Value = iClass Then
GoSub CopyRange
Else
iClass = Range("B" & iRow).Value
iNewRow = iNewRow + 2
GoSub CopyMain
GoSub CopyRange
End If
iRow = iRow + 1
Loop
Application.CutCopyMode = False
Application.StatusBar = False
Application.ScreenUpdating = True
Exit Sub

ErrExit:
MsgBox Err.Description, vbCritical, "错误"
Application.CutCopyMode = False
Application.StatusBar = False
Application.ScreenUpdating = True
Exit Sub

CopyMain:
Application.StatusBar = "正在处理 " & iRow & " / " & iMaxRow & " 行"
Sheets(strSheetName_2).Select
Range("A" & iNewRow) = iClass
iNewRow = iNewRow + 1
Sheets(strSheetName_1).Select
Rows("1:1").Select
Selection.Copy
Sheets(strSheetName_2).Select
Range("A" & iNewRow).Select
Selection.Insert Shift:=xlDown
iNewRow = iNewRow + 1
Sheets(strSheetName_1).Select
Return

CopyRange:
Application.StatusBar = "正在处理 " & iRow & " / " & iMaxRow & " 行"
Rows(iRow & ":" & iRow).Select
Selection.Copy
Sheets(strSheetName_2).Select
Range("A" & iNewRow).Select
Selection.Insert Shift:=xlDown
iNewRow = iNewRow + 1
Sheets(strSheetName_1).Select
Return
End Sub
追问
这么多吗?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式