Sub test()
Dim rng As Range, rngAll As Range
Dim iRandomize As Integer
Dim Spalte As String
Dim SortierSpalte As String
Dim OffsetSpalte As String
Dim rRange As String
Dim Anzahl As Integer
Dim SpaltenKopf
Dim FelderAnzahl As Integer
SpaltenKopf = Array("B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", " _
P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
Anzahl = InputBox("Wie viele Spalten sollen gerechnet werden?")
For FelderAnzahl = 0 To Anzahl - 1
Spalte = SpaltenKopf(FelderAnzahl)
SortierSpalte = Spalte & "2"
OffsetSpalte = Spalte & "10"
rRange = Spalte & "2:" & Spalte & "7"
Set rngAll = Range(rRange)
Randomize
rngAll.ClearContents
For Each rng In rngAll.Cells
iRandomize = Int((49 * Rnd) + 1)
Do Until WorksheetFunction.CountIf(rngAll, iRandomize) = 0
iRandomize = Int((49 * Rnd) + 1)
Loop
rng.Value = iRandomize
Next rng
Range(rRange).Select
Dim sVersion As String
sVersion = Application.Version
Select Case sVersion
Case Is = "11:0"
Selection.Sort Key1:=Range(SortierSpalte), Order1:=xlAscending, Header:=xlGuess, _
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Case Is = "12.0"
ActiveWorkbook.Worksheets(1).Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range( _
SortierSpalte), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(1).Sort
.SetRange Range(rRange)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Select
Next FelderAnzahl
End Sub