2016-06-22 4 views
0

Excel 2013のボタンを使用してマクロを作成し、上記の式で新しい行を挿入します。問題はそれが実行され、私は例えば行10から新しい行11の数式をコピーすると言うすべてはまだ行10に戻って11を読んでいないのですか?上から数式をコピー

Sub Loop_InsertRowsandFormulas() 

Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Risk Input Sheet") 
Dim vRows As Long 
Dim lastCol As Long 
Dim firstRow As Long 

firstRow = InputBox("Enter Row To Start Insert From.") 
vRows = InputBox("Enter Number Of Rows Required") 

If firstRow = 0 Or vRows = 0 Then Exit Sub 
Debug.Print firstRow 
IngA = ws.Cells(5, ws.Columns.Count).End(xlToLeft).Column 
For myLoop = 1 To vRows 
    ws.Range("A" & (firstRow + myLoop)).EntireRow.Insert 
    ws.Range("A" & (firstRow + myLoop) & ":BB" & (firstRow + myLoop)).Formula = ws.Range("A" & firstRow & ":BB" & firstRow).Formula 
Next 

End Sub 
+0

私はそれを単にテキストではなく数式をコピーすることができます。 – Chris

答えて

0

Copy/Pasteを実行する必要があります。例えば、A1が含まれている場合:

=B1+C1 

ランニング:

Sub qwerty() 
    Range("A2").Formula = Range("A1").Formula 
End Sub 

は、同様に=B1+C1A2を残します。

あなたがして、 "調整" するためにコピーされた式したい場合:

Sub ytrewq() 
    Range("A1").Copy Range("A2") 
End Sub 

をEDIT#1:

むしろより:

ws.Range("A" & (firstRow + myLoop) & ":BB" & (firstRow + myLoop)).Formula = ws.Range("A" & firstRow & ":BB" & firstRow).Formula 

使用のようなもの:

ws.Range("A" & firstRow & ":BB" & firstRow).Copy ws.Range("A" & (firstRow + myLoop) & ":BB" & (firstRow + myLoop)) 
+0

申し訳ありませんが、VBAは私にとって初めてのものです。説明できますか?? – Chris

+0

@Chris私の**編集#1 ** –

1

これは何も賞賛を受けることはできません。ありがとうございました。

Sub Loop_InsertRowsandFormulas() 

Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Risk Input Sheet") 
Dim vRows As Long 
Dim lastCol As Long 
Dim firstRow As Long 

firstRow = InputBox("Enter Row To Start Insert From.") 
vRows = InputBox("Enter Number Of Rows Required") 

If firstRow = 0 Or vRows = 0 Then Exit Sub 
Debug.Print firstRow 
IngA = ws.Cells(5, ws.Columns.Count).End(xlToLeft).Column 
For Myloop = 1 To vRows 
    ws.Range("A" & (firstRow + Myloop)).EntireRow.Insert 
    ws.Range("N" & (firstRow) & ":AW" & (firstRow + Myloop)).FillDown 
Next 

End Sub 
+0

を更新していただきありがとうございます。 –

関連する問題