Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: 兰色幻想

VBA第7讲习题---学员答案上传专贴

[复制链接]
发表于 2008-6-16 16:55 | 显示全部楼层

补交作业7课作业

<p>[Power=5] R0MRueA9.rar (45.78 KB, 下载次数: 2)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2008-6-16 22:00 | 显示全部楼层
回复

使用道具 举报

发表于 2008-6-17 01:58 | 显示全部楼层

<p>
游客,如果您要查看本帖隐藏内容请回复
</p><p>&nbsp;+7</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p><font size="2"></font>&nbsp;</p><p><font size="2"></font>&nbsp;</p><p><font size="2"></font>&nbsp;</p><p><font size="2"></font>&nbsp;</p><p><font size="2"></font>&nbsp;</p>
[此贴子已经被laosanjie于2008-6-18 13:41:59编辑过]
回复

使用道具 举报

发表于 2008-6-17 10:31 | 显示全部楼层

[Power=5] <p>第一题:<br/>Sub 隐藏()<br/>Dim x<br/>&nbsp;For x = 1 To 14<br/>&nbsp; If Cells(x, 1) = "" And Cells(x, 2) = "" Then<br/>&nbsp;&nbsp;&nbsp; Rows(x).Hidden = True<br/>&nbsp; End If<br/>&nbsp;Next x<br/>End Sub</p><p>第二题</p><p>Sub 添加()<br/>Dim X As Integer<br/>For X = [A65536].End(xlUp).Row To 3 Step -1<br/>&nbsp; Rows(X &amp; ":" &amp; X + 1).Insert<br/>Next X<br/>End Sub<br/>第三题</p><p>Sub lastblank()<br/>MsgBox Range("A1:d12").Find("", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Address<br/>End Sub</p><p>第四题</p><p>Sub 合并()<br/>Dim X As Integer<br/>&nbsp;For X = 2 To 12<br/>&nbsp;&nbsp; Cells(X, 6) = Cells(X, 5).End(xlToLeft).Value<br/>&nbsp;Next X<br/>End Sub</p><p>第五题</p><p>Sub 取不重复()<br/>Dim MRG As Range<br/>&nbsp;For Each MRG In Range("a1:d12")<br/>&nbsp;&nbsp; If MRG &gt;= "D" And MRG &lt;= "W" Then<br/>&nbsp;&nbsp;&nbsp; If Application.CountIf([F:F], MRG.Value) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; [F65536].End(xlUp).Offset(1, 0) = MRG.Value<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; End If<br/>&nbsp;Next MRG<br/>End Sub</p><p>第六题</p><p>Sub 合并()<br/>Dim x<br/>&nbsp;For x = [a65536].End(xlUp).Row To 2 Step -1<br/>&nbsp;&nbsp; If Cells(x, 1) = Cells(x - 1, 1) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Application.DisplayAlerts = False<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Range(Cells(x, 1), Cells(x - 1, 1)).Merge<br/>&nbsp;&nbsp;&nbsp; Application.DisplayAlerts = True<br/>&nbsp;&nbsp; End If<br/>&nbsp;Next x<br/>End Sub</p><p>第七题</p><p>Sub 累计值()<br/>Dim k As Integer, x As Integer, m As Integer<br/>k = [c65536].End(xlUp).Row + 1<br/>For m = Application.CountA([a1:a15]) To 2 Step -1<br/>&nbsp;&nbsp; x = 0<br/>&nbsp;&nbsp; Do<br/>&nbsp;&nbsp;&nbsp;&nbsp; k = k - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp; x = x + Cells(k, 3)<br/>&nbsp;&nbsp; Loop Until Cells(k, 1) &lt;&gt; ""<br/>&nbsp;Cells(k, 4) = x<br/>&nbsp;Next m<br/>End Sub</p><p>&nbsp;[/Power]</p><p>+7</p>
[此贴子已经被laosanjie于2008-6-18 13:45:04编辑过]
回复

使用道具 举报

发表于 2008-6-17 14:51 | 显示全部楼层

<p>[Power=5] XAjKcufX.rar (48.06 KB, 下载次数: 3)
回复

使用道具 举报

发表于 2008-6-17 19:54 | 显示全部楼层

xuexile
回复

使用道具 举报

发表于 2008-6-17 20:08 | 显示全部楼层

游客,如果您要查看本帖隐藏内容请回复
</p><p>+7</p><p>&nbsp;</p>
[此贴子已经被laosanjie于2008-6-18 13:53:25编辑过]
回复

使用道具 举报

发表于 2008-6-17 21:05 | 显示全部楼层

[Power=5] <p>第1例:隐藏空行<br/>Sub 常规()<br/>Dim x<br/>&nbsp;For x = 1 To 14<br/>&nbsp; If Cells(x, 1) = "" And Cells(x, 2) = "" Then<br/>&nbsp;&nbsp;&nbsp; Rows(x).Hidden = True<br/>&nbsp; End If<br/>&nbsp;Next x<br/>End Sub<br/>Sub 取消隐藏()<br/>&nbsp;Rows("1:15").Hidden = False<br/>End Sub<br/>Sub 隐藏空行() 'by colby<br/>Dim x As Range, y As Range<br/>Set x = Range("A1:A14").SpecialCells(xlCellTypeBlanks)<br/>Set y = Range("b1:b14").SpecialCells(xlCellTypeBlanks).Offset(, -1)<br/>Intersect(x, y).EntireRow.Hidden = True<br/>End Sub<br/>Sub 技巧法()<br/>&nbsp;&nbsp;&nbsp; Rows("1:14").EntireRow.Hidden = True<br/>&nbsp;&nbsp;&nbsp; Range("a1:b15").Select<br/>&nbsp;&nbsp;&nbsp; Selection.RowDifferences(ActiveCell).EntireRow.Hidden = False<br/>End Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp; 第2例:隔行插入空行<br/>Sub 添加空行()<br/>Dim X As Integer<br/>For X = [A65536].End(xlUp).Row To 3 Step -1<br/>&nbsp; Rows(X &amp; ":" &amp; X + 1).Insert<br/>Next X<br/>End Sub<br/>Sub 删除空行()<br/>&nbsp;Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete<br/>End Sub&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; 第3例:查找最后一个空格<br/>Sub b()<br/>MsgBox Range("A1:d12").Find("", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Address<br/>End Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp; 第4例:列的合并<br/>Sub HB()<br/>Dim X As Integer<br/>&nbsp;For X = 2 To 12<br/>&nbsp;&nbsp; Cells(X, 6) = Cells(X, 5).End(xlToLeft).Value<br/>&nbsp;Next X<br/>End Sub&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp; 第5例:取不重复的字母<br/>Sub qu()<br/>Dim MRG As Range<br/>&nbsp;For Each MRG In Range("a1:d12")<br/>&nbsp;&nbsp; If MRG &gt;= "D" And MRG &lt;= "W" Then<br/>&nbsp;&nbsp;&nbsp; If Application.CountIf([F:F], MRG.Value) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; [F65536].End(xlUp).Offset(1, 0) = MRG.Value<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; End If<br/>&nbsp;Next MRG<br/>End Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp; 第6例:合并单元格<br/>Sub hb()<br/>Dim x<br/>&nbsp;For x = [a65536].End(xlUp).Row To 2 Step -1<br/>&nbsp;&nbsp; If Cells(x, 1) = Cells(x - 1, 1) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Application.DisplayAlerts = False<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Range(Cells(x, 1), Cells(x - 1, 1)).Merge<br/>&nbsp;&nbsp;&nbsp; Application.DisplayAlerts = True<br/>&nbsp;&nbsp; End If<br/>&nbsp;Next x<br/>End Sub</p><p>&nbsp;&nbsp;&nbsp;&nbsp; 第7例:查找累计值<br/>'倒循环<br/>Sub a()<br/>Dim k As Integer, x As Integer, m As Integer<br/>k = [c65536].End(xlUp).Row + 1<br/>For m = Application.CountA([a1:a15]) To 2 Step -1<br/>&nbsp;&nbsp; x = 0<br/>&nbsp;&nbsp; Do<br/>&nbsp;&nbsp;&nbsp;&nbsp; k = k - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp; x = x + Cells(k, 3)<br/>&nbsp;&nbsp; Loop Until Cells(k, 1) &lt;&gt; ""<br/>&nbsp;Cells(k, 4) = x<br/>&nbsp;Next m<br/>End Sub<br/>'正循环<br/>Sub b()<br/>&nbsp; Dim x As Integer<br/>&nbsp; For x = 2 To [a65536].End(xlUp).Row<br/>&nbsp;&nbsp;&nbsp; If Cells(x, 1) &lt;&gt; "" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cells(x, 4) = Application.Sum(Cells(x, 1).Offset(0, 2).Resize(Cells(x, 1).MergeArea.Count)) ' (Cells(x, 1).MergeArea.Offset(, 2))<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Next x<br/>End Sub<br/>Sub af()<br/>Dim x, i, a As Integer<br/>Sheets("sheet1").Activate<br/>x = [b65536].End(xlUp).Row<br/>a = x<br/>For i = x To 2 Step -1<br/>If Cells(i, 1) &lt;&gt; "" Then<br/>Cells(i, 4) = Application.Sum(Range(Cells(i, 3), Cells(a, 3)))<br/>a = i - 1<br/>End If<br/>Next<br/>End Sub&nbsp;</p><p>[/Power]</p><p>+7</p><p>&nbsp;</p>
[此贴子已经被laosanjie于2008-6-18 13:56:06编辑过]
回复

使用道具 举报

发表于 2008-6-18 14:51 | 显示全部楼层

游客,如果您要查看本帖隐藏内容请回复
</p><p>+1</p><p>&nbsp;</p>
[此贴子已经被laosanjie于2008-6-18 17:40:51编辑过]
回复

使用道具 举报

发表于 2008-6-18 15:45 | 显示全部楼层

游客,如果您要查看本帖隐藏内容请回复
</p><p>+7</p><p>&nbsp;</p>
[此贴子已经被laosanjie于2008-6-18 17:45:05编辑过]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-7 13:54 , Processed in 0.316565 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表