我正在做的总体思路是通过用户界面(UserForm)获取用户输入,将这些数据添加到一行中,然后我想直接在该原始行下方复制该行“x”次。在此情况下,“x”行数也由用户输入的值确定。
例如,假设用户填写了UserForm并选择了'x'为5。我的VBA代码将获取他们输入的信息,将其放置在第2行,然后基本上将粘贴该行到下面的4个行中。最终结果大致如下(EXCEPT EVERY CELL IN COLUMN C WOULD BE '44', I'M NOT SURE WHY THAT COLUMN DECIDED TO INCREMENT BY 1, BUT THATS ANOTHER THING I NEED HELP FIXING):
例如,假设用户填写了UserForm并选择了'x'为5。我的VBA代码将获取他们输入的信息,将其放置在第2行,然后基本上将粘贴该行到下面的4个行中。最终结果大致如下(EXCEPT EVERY CELL IN COLUMN C WOULD BE '44', I'M NOT SURE WHY THAT COLUMN DECIDED TO INCREMENT BY 1, BUT THATS ANOTHER THING I NEED HELP FIXING):
我假设我可以编写VBA代码来复制并粘贴行x次,但是我认为自动填充会更容易,因为每行的值都相同。 我只是不知道如何指定一个范围,该范围将根据用户输入而变化。 这是我的自动填充特定范围的代码,我不确定如何将其更改为可变范围。
numOfLines = (LastL - FirstL) + 1 'don't worry about how I get this, it's a number that I know is correct
With Sheets("QuoteCSV")
Sheets("QuoteCSV").Select
' Get the current row
Dim curRow As Long
If .Range("B1") = "" Then
curRow = 1
Else
curRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
End If
' Add items to the first row (row 2)
.Cells(curRow, 1) = fson
.Cells(curRow, 2) = fdiv
.Cells(curRow, 3) = fcnum
.Cells(curRow, 4) = fcponum
.Cells(curRow, 5) = frdate
.Cells(curRow, 6) = cname
.Cells(curRow, 7) = add1
.Cells(curRow, 8) = add2
.Cells(curRow, 9) = city
.Cells(curRow, 10) = state
.Cells(curRow, 11) = zip
'Now I want to take that row I just made and autofill it down 'numOfLines' rows
Range("A2:K2").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A2:K6"), Type:=xlFillDefault
'need to change this line to use numOfRows somehow instead of hard-coded range
End With
```
Any help is appreciated!