Excel 如何从上面插入多个带有公式和格式的行(向下按较低的行的格式)?
我是VBA新手,我似乎不太了解这一点。Excel 如何从上面插入多个带有公式和格式的行(向下按较低的行的格式)?,excel,vba,Excel,Vba,我是VBA新手,我似乎不太了解这一点。 我有这个: 在哪里 我想使用VBA: Private Sub Workbook_Open() With Worksheets("Tabelle1") Application.ScreenUpdating = False Dim Limit As Double Limit = 15 Dim nextRow As
我有这个: 在哪里 我想使用VBA:
Private Sub Workbook_Open()
With Worksheets("Tabelle1")
Application.ScreenUpdating = False
Dim Limit As Double
Limit = 15
Dim nextRow As Long
nextRow = 9
Dim Index As Long
For Index = nextRow To Limit Step 1
Rows(nextRow).Insert Shift:=xlShiftDown, CopyOrigin:=xlFormulaFromLeftOrAbove
Range("F" & (Index - 1) & ":H" & (Index - 1)).Copy Range("F" & Index & ":H" & Index)
Next
Application.ScreenUpdating = True
End With
End Sub
要获得以下信息:
F G H
3 =1 =F3+1 =G3+F3
4 =F3+1 =F4+1 =G4+F4
5 =F4+1 =F5+1 =G5+F5
6 =F5+1 =F6+1 =G6+F6
7 =F6+1 =F7+1 =G7+F7
8 =F7+1 =F8+1 =G8+F8
9 =F8+1 =F9+1 =G9+F9
10 =F9+1 =F10+1 =G10+F10
11 =F10+1 =F11+1 =G11+F11
12 =F11+1 =F12+1 =G12+F12
13 =F12+1 =F13+1 =G13+F13
14 =F13+1 =F14+1 =G14+F14
15 =F14+1 =F15+1 =G15+F15
16
Sub Makro4()
With Worksheets("Tabelle1")
Worksheets("Tabelle1").Activate
Application.ScreenUpdating = False
Dim Limit As Double
Limit = 15
Dim nextRow As Long
nextRow = 9
Rows((nextRow) & ":" & (nextRow)).Select
For Index = 1 To (Limit - nextRow + 3) Step 1
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Next
Range("F8:H8").Select
Selection.AutoFill Destination:=Range("F8:H" & (Limit + 2)), Type:=xlFillDefault
Range("A1").Select
Application.ScreenUpdating = True
End With
End Sub
但我明白了:
我以这些作为参考:
范围,因此这可以用一种简单得多的方式完成。AutoFill
可用。您可以阅读文档
这可以用一种简单得多的方式来完成,因为Excel/VBA具有内置的函数
范围。AutoFill
可用。您可以阅读文档
最后我用不同的方法得到了我想要的。我使用Excel的选项录制宏,录制了三种不同的方法,然后编写了以下内容:
F G H
3 =1 =F3+1 =G3+F3
4 =F3+1 =F4+1 =G4+F4
5 =F4+1 =F5+1 =G5+F5
6 =F5+1 =F6+1 =G6+F6
7 =F6+1 =F7+1 =G7+F7
8 =F7+1 =F8+1 =G8+F8
9 =F8+1 =F9+1 =G9+F9
10 =F9+1 =F10+1 =G10+F10
11 =F10+1 =F11+1 =G11+F11
12 =F11+1 =F12+1 =G12+F12
13 =F12+1 =F13+1 =G13+F13
14 =F13+1 =F14+1 =G14+F14
15 =F14+1 =F15+1 =G15+F15
16
Sub Makro4()
With Worksheets("Tabelle1")
Worksheets("Tabelle1").Activate
Application.ScreenUpdating = False
Dim Limit As Double
Limit = 15
Dim nextRow As Long
nextRow = 9
Rows((nextRow) & ":" & (nextRow)).Select
For Index = 1 To (Limit - nextRow + 3) Step 1
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Next
Range("F8:H8").Select
Selection.AutoFill Destination:=Range("F8:H" & (Limit + 2)), Type:=xlFillDefault
Range("A1").Select
Application.ScreenUpdating = True
End With
End Sub
结果:
最后,我用一种不同的方法得到了我想要的东西。我使用Excel的选项录制宏,录制了三种不同的方法,然后编写了以下内容:
F G H
3 =1 =F3+1 =G3+F3
4 =F3+1 =F4+1 =G4+F4
5 =F4+1 =F5+1 =G5+F5
6 =F5+1 =F6+1 =G6+F6
7 =F6+1 =F7+1 =G7+F7
8 =F7+1 =F8+1 =G8+F8
9 =F8+1 =F9+1 =G9+F9
10 =F9+1 =F10+1 =G10+F10
11 =F10+1 =F11+1 =G11+F11
12 =F11+1 =F12+1 =G12+F12
13 =F12+1 =F13+1 =G13+F13
14 =F13+1 =F14+1 =G14+F14
15 =F14+1 =F15+1 =G15+F15
16
Sub Makro4()
With Worksheets("Tabelle1")
Worksheets("Tabelle1").Activate
Application.ScreenUpdating = False
Dim Limit As Double
Limit = 15
Dim nextRow As Long
nextRow = 9
Rows((nextRow) & ":" & (nextRow)).Select
For Index = 1 To (Limit - nextRow + 3) Step 1
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Next
Range("F8:H8").Select
Selection.AutoFill Destination:=Range("F8:H" & (Limit + 2)), Type:=xlFillDefault
Range("A1").Select
Application.ScreenUpdating = True
End With
End Sub
结果:
thanx!此选项插入数字,但不插入行。因此,黑线丢失。那么您希望保留格式吗?抱歉,我看不到问题中指定的内容..是的。。。我把课文写得很短,但写了个标题:Pthanx!此选项插入数字,但不插入行。因此,黑线丢失。那么您希望保留格式吗?抱歉,我看不到问题中指定的内容..是的。。。我把课文写得很短,但在标题中加了一句:我很高兴这行得通,但你应该尽量避免选择。只是一个提示:-)一般的问题是,它会显著降低宏的速度。它是有效的,但你应该避免它作为一个经验法则。包含如何轻松避免的指南。:-)我很高兴这能起作用,但你应该尽量避免选择。只是一个提示:-)一般的问题是,它会显著降低宏的速度。它是有效的,但你应该避免它作为一个经验法则。包含如何轻松避免的指南。:-)