武汉网站建设索王道下拉深圳seo云哥
这节的例子很实用,值得好好学习。最重要的一点,原来复制单元格竟然可以用赋值语句来完成,简直是神操作啊。
Option Explicit'1 单元格输入Sub t1()Range("a1") = "a" & "b"Range("b1") = "a" & Chr(10) & "b" '换行答输入End Sub'2 单元格复制和剪切Sub t2()Range("a1:a10").Copy Range("c1") 'A1:A10的内容复制到C1End SubSub t3()Range("a1:a10").CopyActiveSheet.Paste Range("d1") '粘贴至D1End SubSub t4()Range("a1:a10").CopyRange("e1").PasteSpecial (xlPasteValues) '只粘贴为数值End SubSub t5()Range("a1:a10").CutActiveSheet.Paste Range("f1") '粘贴到f1End SubSub t6()Range("c1:c10").CopyRange("a1:a10").PasteSpecial Operation:=xlAdd '选择粘贴-加End SubSub T7()Range("G1:G10") = Range("A1:A10").ValueEnd Sub
'3 填充公式Sub T8()Range("b1") = "=a1*10"Range("b1:b10").FillDown '向下填充公式End Sub
Option ExplicitSub c1()Rows(4).Insert
End SubSub c2() '插入行并复制公式Rows(4).InsertRange("3:4").FillDownRange("4:4").SpecialCells(xlCellTypeConstants) = ""
End SubSub c3()Dim x As IntegerFor x = 2 To 20If Cells(x, 3) <> Cells(x + 1, 3) ThenRows(x + 1).Insertx = x + 1End IfNext x
End SubSub c4()Dim x As Integer, m1 As Integer, m2 As IntegerDim k As Integerm1 = 2For x = 2 To 1000If Cells(x, 1) = "" Then Exit SubIf Cells(x, 3) <> Cells(x + 1, 3) Thenm2 = xRows(x + 1).InsertCells(x + 1, "c") = Cells(x, "c") & " 小计"Cells(x + 1, "h") = "=sum(h" & m1 & ":h" & m2 & ")"Cells(x + 1, "h").Resize(1, 4).FillRightCells(x + 1, "i") = ""x = x + 1m1 = m2 + 2End IfNext x
End Sub
Sub c44()
'个人方法
Dim x As Integer
Dim t As Integer
t = Range("c65536").End(xlUp).Row
For x = t To 2 Step -1If Cells(x, 3) <> Cells(x - 1, 3) ThenRows(x).InsertCells(Cells(x, "C").Offset(1, 0).End(xlDown).Row + 1, "C") = Cells(Cells(x, "C").Offset(1, 0).End(xlDown).Row, "C") & " 小计"Cells(Cells(x, "H").Offset(1, 0).End(xlDown).Row + 1, "H") = _Application.Sum(Range(Cells(x, "h").Offset(1, 0), Cells(x, "H").Offset(1, 0).End(xlDown)))End If
Next x
End SubSub dd() '删除小计行Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub