Hi,
being a complete newbee in VBA I am struggling with something that is probably very simple.
I have a range that consists of any number of rows, and any number of columns, but not very many. Up to 500 rows and 30 columns. The columns may be grouped by a heading, and a group may be from 2 - 5 columns. It will always be the same number of columns in a group.
What I want to do is to move these groups under each other.
Let's say that the range has 20 rows, and 18 columns. Each group of columns has 3 columns. (Col 1-3 belongs together, 4-6, 7-9 and so on) Then I want col 4-6 to be moved under 1-3, 7-9 under 4-6 and so on.
This is my code so far:
Sub MoveCols()
Dim mR As Range
On Error Resume Next
Set mR = Application.InputBox("Select your Range", , , , , , , 8)
If mR Is Nothing Then MsgBox "Nothing Selected!", vbExclamation: Exit Sub
On Error GoTo 0
Dim HowManyTimes As Integer: HowManyTimes = 1
mR.Copy mR.Offset(mR.Rows.Count).Resize(mR.Rows.Count * HowManyTimes)
End Sub
The ideal solution would be that after I have selected to complete range, from i.e. "A1: R20" I will get a new inputbox where I can enter a number representing the number of columns in each group. When this is done the range is being split by the number in the inputbox, and each group is moved under each other. So if I enter 3 there will be in total 6 groups with 3 columns in each. The range will of course always be split into a number that matches the total number of columns.
Could anyone please point me into the right direction on how to do that?
being a complete newbee in VBA I am struggling with something that is probably very simple.
I have a range that consists of any number of rows, and any number of columns, but not very many. Up to 500 rows and 30 columns. The columns may be grouped by a heading, and a group may be from 2 - 5 columns. It will always be the same number of columns in a group.
What I want to do is to move these groups under each other.
Let's say that the range has 20 rows, and 18 columns. Each group of columns has 3 columns. (Col 1-3 belongs together, 4-6, 7-9 and so on) Then I want col 4-6 to be moved under 1-3, 7-9 under 4-6 and so on.
This is my code so far:
Sub MoveCols()
Dim mR As Range
On Error Resume Next
Set mR = Application.InputBox("Select your Range", , , , , , , 8)
If mR Is Nothing Then MsgBox "Nothing Selected!", vbExclamation: Exit Sub
On Error GoTo 0
Dim HowManyTimes As Integer: HowManyTimes = 1
mR.Copy mR.Offset(mR.Rows.Count).Resize(mR.Rows.Count * HowManyTimes)
End Sub
The ideal solution would be that after I have selected to complete range, from i.e. "A1: R20" I will get a new inputbox where I can enter a number representing the number of columns in each group. When this is done the range is being split by the number in the inputbox, and each group is moved under each other. So if I enter 3 there will be in total 6 groups with 3 columns in each. The range will of course always be split into a number that matches the total number of columns.
Could anyone please point me into the right direction on how to do that?