Excel精英培训网

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

[习题] 【v1-6综合练习题2】卡片转数据表格式存放

[复制链接]
发表于 2007-12-19 14:01 | 显示全部楼层

学习了do loop 试验了一下

Sub CardToTable()<br/>Dim i As Long, No As Long, m&amp;, n&amp;, x&amp;<br/>No = Sheets("卡片").Range("A:A").Find("姓名", , xlValues, xlWhole, , xlPrevious).Row \ 5 + 1<br/>i = 0<br/>t = Timer<br/>Do<br/>m = 5 * i + 1<br/>n = 5 * i + 4<br/>x = i + 2<br/>Sheets("卡片").Range("B" &amp; m &amp; ":B" &amp; n).Copy<br/>Cells(x, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True<br/>i = i + 1<br/>Loop Until i = No<br/>MsgBox Timer - t<br/>End Sub<br/>
[此贴子已经被作者于2007-12-19 14:10:36编辑过]
回复

使用道具 举报

发表于 2007-12-19 22:14 | 显示全部楼层

<p>Sub 卡片转移()<br/>Dim x%, k%<br/>With Sheets("卡片")<br/>k = 2</p><p>For x = 1 To .Range("a65536").End(xlUp).Row Step 5<br/>Cells(k, 1) = .Cells(x, 2)<br/>Cells(k, 2) = .Cells(x + 1, 2)<br/>Cells(k, 3) = .Cells(x + 2, 2)<br/>Cells(k, 4) = .Cells(x + 3, 2)<br/>k = k + 1<br/>Next x</p><p>End With<br/>End Sub</p><p>名字E和I 上面多了一个名字A! 开始时没留意,调试一晚上一直显示不正确,后来一个一个运行,才发现是那里出了问题,真晕!</p><p></p>做完后看贴子才发现高手真多,我是中规中距的一步一步的做。[em04]
[此贴子已经被作者于2007-12-19 22:21:16编辑过]
回复

使用道具 举报

发表于 2007-12-20 11:49 | 显示全部楼层

<p>Sub 转换()<br/>&nbsp;&nbsp;&nbsp; Dim k&amp;<br/>&nbsp;&nbsp;&nbsp; With Sheets("卡片")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For k = 0 To .Range("A65536").End(xlUp).Row<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cells(k \ 5 + 2, (k Mod 5) + 1) = .Range("B" &amp; k + 1).Value<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next k<br/>&nbsp;&nbsp;&nbsp; End With<br/>End Sub</p><p>未考虑多出姓名的</p>
回复

使用道具 举报

发表于 2007-12-21 12:56 | 显示全部楼层

Sub BeyondPC6_2()<br/>Dim i%, x%, y%<br/>With Sheets("卡片")<br/>x = 0<br/>y = 2<br/>For i = 1 To .Range("A65536").End(xlUp).Row<br/>&nbsp;&nbsp;&nbsp; If i Mod 5 &lt;&gt; 0 Then<br/>&nbsp;&nbsp;&nbsp; x = x + 1<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; x = 1<br/>&nbsp;&nbsp;&nbsp; i = i + 1<br/>&nbsp;&nbsp;&nbsp; y = y + 1<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Sheets("数据表").Cells(y, x) = .Cells(i, 2)<br/>Next i<br/>End With<br/>End Sub
回复

使用道具 举报

发表于 2007-12-22 14:02 | 显示全部楼层

Sub 卡片()<br/>Dim x%, y%<br/>y = 2<br/>With Sheets("卡片")<br/>&nbsp; For x = 1 To .Range("b65536").End(xlUp).Row Step 5<br/>&nbsp;&nbsp; Cells(y, 1) = .Cells(x, 2).Value<br/>&nbsp;&nbsp; Cells(y, 2) = .Cells(x + 1, 2).Value<br/>&nbsp;&nbsp; Cells(y, 3) = .Cells(x + 2, 2).Value<br/>&nbsp;&nbsp; Cells(y, 4) = .Cells(x + 3, 2).Value<br/>&nbsp;&nbsp; y = y + 1<br/>&nbsp; Next<br/>End With<br/>End Sub<br/>
回复

使用道具 举报

发表于 2007-12-22 17:03 | 显示全部楼层

Sub ttt2()<br/>&nbsp;With Sheets("数据表")<br/>&nbsp;aab = Sheets("卡片").Range("a65536").End(xlUp).Row<br/>&nbsp;For i = 1 To aab Step 5<br/>&nbsp;For j = 1 To 4<br/>&nbsp;aaa = .Range("a65536").End(xlUp).Row + 1<br/>&nbsp;.Cells(aaa, j) = Sheets("卡片").Cells(j + i - 1, 2)<br/>&nbsp;Next j<br/>&nbsp;Next i<br/>&nbsp;End With<br/>End Sub
回复

使用道具 举报

发表于 2007-12-23 02:53 | 显示全部楼层

<p>?/p>[em01]
回复

使用道具 举报

发表于 2007-12-23 15:31 | 显示全部楼层

Sub TT1()<br/>Dim X, y, z As Integer<br/>For X = 1 To Sheets("卡片").Range("A65536").End(xlUp).Row \ 5<br/>y = Sheets("数据表").Range("A65536").End(xlUp).Row + 1<br/>&nbsp; For z = 1 To 4<br/>&nbsp;&nbsp;&nbsp;&nbsp; Sheets("数据表").Cells(y, z) = Sheets("卡片").Cells((X - 1) * 5 + z, 2)<br/>&nbsp; Next z<br/>Next X<br/>End Sub<br/>
回复

使用道具 举报

发表于 2007-12-29 11:38 | 显示全部楼层

<div class="msgheader">QUOTE:</div><div class="msgborder"><b>以下是引用<i>cfq-xxj</i>在2007-12-18 22:43:00的发言:</b><br/><div class="msgheader">QUOTE:</div><div class="msgborder"><b>以下是引用<i>mjm96511</i>在2007-12-18 22:37:00的发言:</b><br/>Sub 数据转换()<br/>Dim a As Integer, b As Integer<br/>a = Sheets("卡片").Range("A65536").End(xlUp).Row<br/>For i = 1 To Int(a / 5)<br/>&nbsp;&nbsp;&nbsp; For j = 1 To 4<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = 5 * (i - 1) + j<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheets("数据表").Cells(i, j) = Sheets("卡片").Cells(b, 2)<br/>&nbsp;&nbsp;&nbsp; Next<br/>Next<br/>End Sub</div><p>高手</p></div><p></p>为什么用这些代码我运行后结果不对??[em01]
回复

使用道具 举报

发表于 2008-2-4 15:56 | 显示全部楼层

<p>Sub bb()<br/>Dim a As Long<br/>Dim b As Long<br/>b = 1<br/>For a = 1 To 100 Step 5<br/>&nbsp;With Sheets("数据表")<br/>&nbsp;.Cells(b + 1, 1) = Sheets(1).Cells(a, 2)<br/>&nbsp;.Cells(b + 1, 2) = Sheets(1).Cells(a + 1, 2)<br/>&nbsp;.Cells(b + 1, 3) = Sheets(1).Cells(a + 2, 2)<br/>&nbsp;.Cells(b + 1, 4) = Sheets(1).Cells(a + 3, 2)<br/>&nbsp; b = b + 1<br/>End With<br/>Next a<br/>End Sub</p><p>老师表中有两个格是有两个名字的,是故意这样的,还是写错了。我是按每个人都是4格子写的。<br/></p>
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-29 05:28 , Processed in 0.224582 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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