Hello everyone. Hope all are doing well.
I needed help in writing a VBA code with arguments for a range (rng) and n that will shift the elements of an (m x 1) range up by n rows. The first n rows of the range rng will “wrap around” and appear at the bottom of the resulting vector. If anybody could help me out with the code using the elements that i have dimmed so that its easy for me to understand, it would be of great help.
I have attached an image for reference.
Option Explicit
Option Base 1
Function ShiftVector (rng As Range, n As Integer)
Dim nr As Integer, B() As Variant, i As Integer
nr = rng.Rows.Count
ReDim B(nr, 1)
B = rng
If i > (nr - n) Then
i = i + 1
ShiftVector = WorksheetFunction.Transpose(B)
End Function
I tried this much but couldn't move ahead of this.
Many thanks,
Ria
I needed help in writing a VBA code with arguments for a range (rng) and n that will shift the elements of an (m x 1) range up by n rows. The first n rows of the range rng will “wrap around” and appear at the bottom of the resulting vector. If anybody could help me out with the code using the elements that i have dimmed so that its easy for me to understand, it would be of great help.
I have attached an image for reference.
Option Explicit
Option Base 1
Function ShiftVector (rng As Range, n As Integer)
Dim nr As Integer, B() As Variant, i As Integer
nr = rng.Rows.Count
ReDim B(nr, 1)
B = rng
If i > (nr - n) Then
i = i + 1
ShiftVector = WorksheetFunction.Transpose(B)
End Function
I tried this much but couldn't move ahead of this.
Many thanks,
Ria