Evenly distribute a short column of values into a longer column

opus13

New Member
Joined
Mar 14, 2012
Messages
5
Is there a way to even distribute the contents of one column into another?

I've got a column of 19,268 values, and need to (roughly) evenly distribute another 732 values into the column.


A1
A
B 2
B
C3
1
D

C
E
-->D
F

2



E



F



3




<tbody>
</tbody>

Illustrations always say it easier than words.

Thanks.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
This might work for you. I've assumed that the first data is in A1 down, and the new data in B1 down.

Code:
Sub Insert_Other_Data()
Dim lOrigDataRows As Long, lNewData As Long, lGroupRows As Long
lOrigDataRows = Range("A" & Rows.Count).End(xlUp).Row
lNewData = Range("B" & Rows.Count).End(xlUp).Row
lGroupRows = Int(lOrigDataRows / lNewData)
Temp = Range("B1:B" & lNewData)
'insert last number
Range("A" & lOrigDataRows + 1) = Temp(UBound(Temp), 1)
For i = lNewData - 1 To 1 Step -1
    'insert blank row
    Rows(i * lGroupRows).Insert
    'insert next value
    Cells(i * lGroupRows, 1).Value = Temp(i, 1)
Next i
End Sub
 
Upvote 0
This might work for you. I've assumed that the first data is in A1 down, and the new data in B1 down.

Code:
Sub Insert_Other_Data()
...
End Sub

You, dear sir, are one that I owe a beer. Thank you. Next time you happen to be Colorado, let me know and i'll make good on it :cool:.

Just for fun, this is what that string running on a column of 732 going into a column of 19,268 looks like in system usage.

col-merge.png
 
Upvote 0
Hi there,

Here is my try. A bit longer, but I tried to keep the interspersing as "even" as possible if that makes sense.

With the 19268 values in Col A and the 732 values in Col B (both starting at row 2), like (truncated of course) :
Excel Workbook
ABCDE
1Long ColumnShort ColumnResults
2an1an
3ana2ana
4anabaena3anabaena
5anabantidae4anabantidae
6anabaptism5anabaptism
7anabaptist6anabaptist
8anabaptistic7anabaptistic
9anabaptistical8anabaptistical
10anabaptistically9anabaptistically
11anabaptistry10anabaptistry
12anabaptize11anabaptize
13anabas12anabas
14anabasine13anabasine
15anabasis14anabasis
16anabasse15anabasse
17anabata16anabata
18anabathmos17anabathmos
19anabatic18anabatic
20anabel19anabel
21anaberoga20anaberoga
22anabibazon21anabibazon
23anabiosis22anabiosis
24anabiotic23anabiotic
25anablepidae24anablepidae
26anableps25anableps
27anabo26anabo
28anabohitsite271
29anabolic28anabohitsite
Sheet1
Excel 2010

In a Standard module:

Rich (BB code):
Option Explicit
    
Public Sub IntersperseValues()
Dim rngLong As Range
Dim rngShort As Range
  
Dim arrMoreVals As Variant
Dim arrLessVals As Variant
  
Dim dblRemainder As Double
Dim dblLeftOver As Double
Dim dblAccurateRatio As Double
  
Dim lngRatio As Long
Dim Extra As Long
Dim n As Long, i As Long, j As Long, k As Long
  
  With Sheet1
    Set rngLong = .Range(.Range("A2"), RangeFound(.Range(.Cells(2, 1), .Cells(.Rows.Count, 1))))
    Set rngShort = .Range(.Range("B2"), RangeFound(.Range(.Cells(2, 2), .Cells(.Rows.Count, 2))))
  End With
  
  arrMoreVals = rngLong.Value
  arrLessVals = rngShort.Value
  
  ReDim arrAllVals(1 To (UBound(arrMoreVals, 1) + UBound(arrLessVals, 1)), 1 To 1)
  
  dblAccurateRatio = UBound(arrMoreVals, 1) / UBound(arrLessVals, 1)
  
  lngRatio = Int(dblAccurateRatio)
  dblRemainder = dblAccurateRatio - lngRatio
  
  Do While j< UBound(arrAllVals, 1)
    
    dblLeftOver = dblLeftOver + dblRemainder
    
    If dblLeftOver >= 1 Then
      dblLeftOver = dblLeftOver - Int(dblLeftOver)
      Extra = 1
    Else
      Extra = 0
    End If
    
    For i = 1 To (lngRatio + Extra)
      
      n = n + 1
      If n<= UBound(arrMoreVals, 1) Then
        j = j + 1
        arrAllVals(j, 1) = arrMoreVals(n, 1)
      Else
        Exit For
      End If
    Next
    
    k = k + 1
    If k<= UBound(arrLessVals, 1) Then
      j = j + 1
      arrAllVals(j, 1) = arrLessVals(k, 1)
    End If
  Loop
  
  Sheet1.Range("E2").Resize(UBound(arrAllVals, 1)).Value = arrAllVals
  
End Sub
  
Function RangeFound(SearchRange As Range, _
                    Optional ByVal FindWhat As String = "*", _
                    Optional StartingAfter As Range, _
                    Optional LookAtTextOrFormula As XlFindLookIn = xlValues, _
                    Optional LookAtWholeOrPart As XlLookAt = xlPart, _
                    Optional SearchRowCol As XlSearchOrder = xlByRows, _
                    Optional SearchUpDn As XlSearchDirection = xlPrevious, _
                    Optional bMatchCase As Boolean = False) As Range
    
    If StartingAfter Is Nothing Then
        Set StartingAfter = SearchRange(1)
    End If
    
    Set RangeFound = SearchRange.Find(What:=FindWhat, _
                                      After:=StartingAfter, _
                                      LookIn:=LookAtTextOrFormula, _
                                      LookAt:=LookAtWholeOrPart, _
                                      SearchOrder:=SearchRowCol, _
                                      SearchDirection:=SearchUpDn, _
                                      MatchCase:=bMatchCase)
End Function

Hope that helps,

Mark
 
Upvote 0
You are welcome.

And the beer is safe, I haven't been to Colorado in 7 years though at one point I was going through there every 3 months, and all I saw was the Rockies (fantastic view when landing) and Denver airport :).
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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