So I'm trying to create a function in VBA that will take 4 parameters from the user.
- Value to be input into the range
- Beginning of the Range
- End of the Range
- A number defining every Nth row (3 would be every 3rd row, 4 would be every 4th, etc.)
I want the function to take the value and apply it to every Nth row in that range. Here is what I have so far:
Sub InsertValueEveryNthRow()
Dim StartRng As String
Dim EndRng As String
Dim rng As String
Dim RangeValue As Range
Dim InputValue As Double
InputValue = InputBox("Enter value to be input. (1234.56)")
StartRng = InputBox("Enter cell to begin operation on. (E3)")
EndRng = InputBox("Enter cell to end operation on. (G21)")
Interval = InputBox("Enter row interval. (3 = every third row)")
rng = StartRng & ":" & EndRng
Set RangeValue = Range(rng)
For i = 1 To RangeValue.Rows.Count Step Interval
RangeValue.Value = InputValue
Next I
End Sub
It does everything so far but inputs the value in every row in the range.
I'm trying to get back into VBA so I'm sure my code isn't that efficient or well made, but it only needs to work for maybe 100 rows at a time to start. Any help would be greatly appreciated, thanks.