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.
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.