根据单元格值将行添加到工作表

我GOOGLE了,并尝试了各种不同的东西,让这个工作,但仍然无法find一个解决scheme。

我仍然试图了解macros和VB,所以任何帮助将不胜感激。

基本上,我所追求的是一个工作表上的单元格值是第二个工作表上的行数。

图片显示我以后

在这里输入图像说明

如图所示,源单元的价值(付款数量)取决于协议的期限/频率/价值。 然后我会喜欢在下一个工作表中分配的行数,并按顺序编号。

这是我迄今为止设法摸索的东西….

Sub ExtendByValue() ' ' ExtendByValue Macro ' Extends the rows by the number of repayments ' ' Sheets("Agreement Tems").Select Range("C8").Select Selection.Copy Sheets("Payments").Select Range("M1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Rows("8:8").Select Application.CutCopyMode = False Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove End Sub 

任何帮助,这是表示赞赏。

  Rows("8:" & (sheets("agreementterms").range("c8").Value + 8)).select Selection.insert shift:=xldown 

如果您有意见中指定的价值问题,请使用以下内容。

  Rows("8:" & (sheets("agreementterms").range("c8").text + 8)).select Selection.insert shift:=xldown 

尝试这个

 Option Explicit Sub ExtendByValue() ' ' ExtendByValue Macro ' Extends the rows by the number of repayments ' Dim nRows As Long nRows = CLng(Sheets("Agreement Tems").Range("C8")) 'get the integer part of cell "C8" value in "Agreement Tems" sheet With Sheets("Payments") .Range("B8").Resize(nRows - 1).EntireRow.Insert 'insert nRows-1 below cell "B8" of "Payments" sheet, so as to have nRows with this latter included With .Range("B8").Resize(nRows) 'of these nRows ... .FormulaR1C1 = "=row()- row(R7)" ' ... fill column "B" with a formula returning integer form 1 to nRows ... .Value = .Value ' ... and finally get rid of formulas and leave only values End With End With End Sub