AW: Auswählen und Markieren
14.05.2004 11:24:57
Heinz
Hallo Diana,
hier noch eine Möglichkeit, mit der du alles variabel bestimmen kannst. Der Bereich wird ausgewählt, daraus die Zeilenanzahl berechnet, und weiters die Anzahl der gewünschten Auswahlzellen eingegeben.
Sub Zufall3()
Dim Bereich As Range, F As Boolean
Dim s%, z%, i%, za%, ze%, sa%, se%, z1%, s1%, Anz%
Set Bereich = Application.InputBox("Bereich", Type:=8)
Anz = InputBox("Wieviele Zahlen sollen ausgewählt werden?")
za = Bereich.Cells(1).Row
ze = Bereich.Cells(Bereich.Cells.Count).Row
sa = Bereich.Cells(1).Column
se = Bereich.Cells(Bereich.Cells.Count).Column
z1 = ze - za + 1
s1 = se - sa + 1
Bereich.Interior.ColorIndex = xlNone
For i = 1 To Anz
F = True
While F = True
z = Int((z1 * Rnd) + 1)
s = Int((s1 * Rnd) + 1)
If Cells(z + za - 1, s + sa - 1).Interior.ColorIndex > 1 Then F = True Else F = False
Wend
Cells(z + za - 1, s + sa - 1).Interior.ColorIndex = 35
Next
End Sub
Gruß
Heinz