how to spread data evenly in multiple rows

zgsharon

New Member
Joined
May 19, 2016
Messages
3
I found this code online and was wondering if someone could tell me how to make this work for more than one column at once? The code inserts a specific number of blank spaces into a column of data. I just need to do it for 3 or 4 columns at once and am having some problems altering the code. Any help would be greatly appreciated.

Sub MG28Sep05()
Dim Last As Integer, n
' Change "A" Below To another column Letter
Last = Range("A" & Rows.Count).End(xlUp).row

For n = Last To 2 Step -1
' Change "7" Below To No of Blank Rows Required
Cells(n, 1).Resize(7).Insert shift:=xlDown
Next n
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Change Resize(7) to Resize(7,3) or Resize(7,4) depending on how many columns you need it for. Should work.
 
Upvote 0
Thank you DKaur. That worked like a charm. Do you know if there is a way to get the data to spread a random value of rows over a given range? So in some cases there might be 4 blank rows in between numbers and in another case there would only be 2 or 3. If I start with the data below and run the code, I'd want it to look like the second example where the start and end values of columns A, B and C match those of D, E and F with a random value of blank rows placed in between.
ABCDEF
666554
454545644523
44443423
555234234
64465
234645
24243
33434
5423
6561
42332

<tbody>
</tbody>

After running code- I just need the first and last rows of columns A, B and C to line up with D, E, and F, with random blanks placed in between. So there are 3 blank spaces and then only two after the row of 4's.

ABCDEF
666554
644523
43423
234234
45454564465
234645
24243
33434
4445423
6561
42332
55523412

<tbody>
</tbody>
 
Upvote 0
How about this:

Sub MG28Sep05()
Dim Last, EndRow, n, y As Integer
' Change "A" Below To another column Letter
Last = Range("A" & Rows.Count).End(xlUp).Row
EndRow = Range("D" & Rows.Count).End(xlUp).Row


For n = Last To 2 Step -1
If n = Last Then
Cells(n, 1).Resize(EndRow - Last, 3).Insert shift:=xlDown
Else
Cells(n, 1).Resize(1, 3).Cut
y = n * ((EndRow) / (Last))
Cells(y, 1).Select
ActiveSheet.Paste
End If
Next n


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,021
Messages
6,128,319
Members
449,440
Latest member
Gillian McGovern

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top