</p><p>第5、7两题,重新看了录像,才明白。</p><p>第一题:隐藏A和B列都为空的行。</p><p>Sub 隐藏()<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</p><p>第二题:隔行插入空行</p><p>Sub 隔行插入空行()<br/> Dim i%, z%<br/> On Error GoTo 100<br/>100:<br/> z = InputBox("请输入每行间插入的空行数量", "确定想插入的行数")<br/> For i = Range("b65536").End(xlUp).Row To 3 Step -1<br/> Rows(i & ":" & i + z - 1).Insert<br/> Next i<br/>End Sub</p><p>第三题:查找最右最下空值的单元格</p><p>Sub 查找空单元()<br/> MsgBox "最右最下空值单元格地址是:" & Range("a1:d12").Find("", searchorder:=xlByRows, searchdirection:=xlPrevious).Address(0, 0)<br/>End Sub</p><p>第四题:列的合并</p><p>Sub 合并()<br/> Dim x%<br/> For x = 2 To 12<br/> Cells(x, "f") = Cells(x, "e").End(xlToLeft)<br/> Next x<br/>End Sub</p><p>第五题:取不重复值</p><p>Sub 取不重复值()<br/> Dim aa As Range<br/> For Each aa In Range("a1:d12")<br/> If aa >= "D" And aa <= "W" Then<br/> If Application.CountIf(Range("f:f"), aa) = 0 Then<br/> Range("f65536").End(xlUp).Offset(1, 0) = aa<br/> End If<br/> End If<br/> Next aa<br/>End Sub</p><p>第六题:合并单元格</p><p>Sub 合并单元格()<br/> Dim x%<br/> For x = Range("a65536").End(xlUp).Row To 2 Step -1<br/> If Cells(x, 1) = Cells(x - 1, 1) Then<br/> Application.DisplayAlerts = False<br/> Range(Cells(x, 1), Cells(x - 1, 1)).Merge<br/> End If<br/> Next x<br/> Application.DisplayAlerts = True<br/>End Sub</p><p>第七题:求和</p><p>Sub 求和()<br/> Dim x%<br/> For x = 2 To Range("c65536").End(xlUp).Row<br/> If Cells(x, 1) <> "" Then<br/> Cells(x, 4) = Application.Sum(Cells(x, 3).Resize(Cells(x, 1).MergeArea.Count))<br/> End If<br/> Next x<br/>End Sub<br/></p><p>[/hide]</p><p>+7</p><p> </p>
[此贴子已经被laosanjie于2008-6-20 20:48:54编辑过] |