Problem with joining number columns

Skewp
05-13-2010, 03:02 PM
Hey, I need a bit help with joining columns of numbers. I need a macro to make two N elements long columns of numbers and sort them from lowest to highest. After that it needs to join both of the columns into one column. It is important, that it sorts the numbers in the way that it takes the lowest number of both columns, puts it into another cell, then finds the next lowest and adds to the newly made column.

I managed to make the n elements long columns part:


Sub jadad()

Dim i, j, var As Integer
Worksheets("Leht1").UsedRange.Clear 'kustutab

s1 = Val(InputBox("Sisesta jada elementide arv"))
3 For i = 1 To s1
Cells(i, 1) = Int(Rnd() * 99 + 1) 'annab arvu 1-100
Next i

Dim t, v, max
Set t = Range("a1").CurrentRegion 'otsib ơige lahtri
v = t.Rows.Count
For i = 1 To v - 1
For j = i + 1 To v
If t.Cells(i, 1) > t.Cells(j, 1) Then
abi = t.Cells(i, 1)
t.Cells(i, 1) = t.Cells(j, 1)
t.Cells(j, 1) = abi
End If
Next j
Next i

s2 = Val(InputBox("Sisesta jada elementide arv"))
For j = 1 To s2
Cells(j, 2) = Int(Rnd() * 99 + 1)
Next j

Dim k, l, min
Set k = Range("b1").CurrentRegion 'otsib ơige lahtri
l = k.Rows.Count
For i = 1 To l - 1
For j = i + 1 To l
If k.Cells(i, 2) > k.Cells(j, 2) Then
abi = k.Cells(i, 2)
k.Cells(i, 2) = k.Cells(j, 2)
k.Cells(j, 2) = abi
End If
Next j
Next i
End Sub



How could I join them into one column from lowest to highest? For example, in the D column.

elmonkfish
05-17-2010, 09:44 AM
This will take first 5 values of column A and first 5 of B and then put them into column C sorting them in process. Is that example you were looking for?

Set R1 = Range("A1:A5")
Set R2 = Range("B1:B5")
nn = 1
For Each N In R1
Cells(nn, 3) = N.Value2
nn = nn + 1
Next N
For Each N In R2
Cells(nn, 3) = N.Value2
nn = nn + 1
Next N
Set R3 = Range("C1:C" & nn)
Call R3.Sort(R3)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum