Option Base 1
Sub Jämna_udda()
Dim iTal(), iSorteradeTal
ReDim iTal(Selection.Cells.Count)
For i = 1 To Selection.Cells.Count
iTal(i) = InputBox("Skriv in tal " & i)
Next
For i = 1 To Selection.Cells.Count
iCell = iCell + 1
Selection.Cells(iCell).Value = iTal(i)
Next
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending ' (xlDescending för fallande ordning)
iSorteradeTal = Selection.Cells
iCell = 0
For i = 1 To Selection.Cells.Count
If iSorteradeTal(i, 1) / 2 = Int(iSorteradeTal(i, 1) / 2) Then
iCell = iCell + 1
Selection.Cells(iCell).Value = iSorteradeTal(i, 1)
End If
Next
For i = 1 To Selection.Cells.Count
If iSorteradeTal(i, 1) / 2 <> Int(iSorteradeTal(i, 1) / 2) Then
iCell = iCell + 1
Selection.Cells(iCell).Value = iSorteradeTal(i, 1)
End If
Next
End Sub
----------------------------------------------------------------------
Plockar in i en inputbox och skriver talen temporärt i markeringen där dom sorteras. Läser sen in dom sorterade, går igenom dom två gånger och skriver över i markeringen. I varv 1 skrivs dom tal vars hälft är samma som dess hälft utan decimal (ex. 6 / 2 = 3, oavsett om ev. decimal tas bort - dvs JÄMNT). Varv 2 fyller på med dom vars hälft skiljer sig från dess hälft med kapad decimal (ex. 9 / 2 = 4,5... men bara 4 om decimalen kapas - dvs UDDA).