Michael515
Board Regular
- Joined
- Jul 10, 2014
- Messages
- 136
Hi Y'all,
I have a worksheet that inserts rows based on the value in a certain cell. The problem is, is that on this same worksheet, I would like to create to other cells that insert rows below it based on the value inside it. The problem is, that after the rows are inserted into the worksheet the first time, the other "trigger" cells become displaced in the code. I feel like I have to use a combination of dim variables and offsets but don't know exactly how. Here's the code I've been working on below:
I'm new to writing VBA so any tips for the future would be much appreciated. If I haven't described my problem clearly enough, please feel free to ask me more questions so I can clarify. Thank you for all the help!
I have a worksheet that inserts rows based on the value in a certain cell. The problem is, is that on this same worksheet, I would like to create to other cells that insert rows below it based on the value inside it. The problem is, that after the rows are inserted into the worksheet the first time, the other "trigger" cells become displaced in the code. I feel like I have to use a combination of dim variables and offsets but don't know exactly how. Here's the code I've been working on below:
Code:
Sub InsertFundRows()
Dim i As Integer, n As Integer, m As Long
n = Sheets("Questionnaire").Range("B20").Value
m = Sheets("Questionnaire").Range("B30").Row
For i = 1 To n
Rows(m + 1 * i).Insert
Next i
End Sub
Sub InsertFundRows2()
Dim i As Integer, n As Integer, m As Long
Dim x As Variable
Dim y As Variable
x = Sheets("Questionnaire").Range("D108").Offset(Range("B20").Value, 0)
n = x.Value
y = Sheets("Questionnaire").Range("B111").Offset(Range("B20").Value, 0)
m = y.Row
For i = 1 To n
Rows(m + 1 * i).Insert
Next i
End Sub
I'm new to writing VBA so any tips for the future would be much appreciated. If I haven't described my problem clearly enough, please feel free to ask me more questions so I can clarify. Thank you for all the help!