Per Inputbox Zufallszahlen in Zellbereich ohne doppelte
13.05.2025 17:20:30
Dieter(Drummer)
In der Musterdatei wird im Bereich B3:B8 ein Zahl von + 10 und minus 10, ohne doppelte erzeugt. Das funktioniert.
Im Code: "Zufall", suche ich die Möglichkeit, per Inputbox, den Bereich und die Zufallszahlen im neuen Bereich, ohne doppelte, einzugeben.
Der max- und min Zahlenbereich soll per Inputbox definierbar und ausführbar sein.
Falls es auch möglich ist, den neuen Bereich im Code: "Farbbalken_im_Bereich", auch zu übernehmen, wäre es super.
Mit der Bitte um Hilfe, grüßt
Dieter(Drummer)
Musterdatei:
https://www.herber.de/bbs/user/177431.xlsm
Code "Zufall"
'Herber:https://www.herber.de/mailing/Zufallszahlen_generieren_die_sich_nicht_wiederholen.htm
Sub Zufall() 'Ohne doppelte
Dim rng As Range, rngAll As Range
Dim iRandomize As Integer
Set rngAll = Range("B3:B8")
Randomize
rngAll.ClearContents
For Each rng In rngAll.Cells
iRandomize = Int((10 * Rnd) + 1)
Do Until WorksheetFunction.CountIf(rngAll, iRandomize) = 0
iRandomize = Int((10 * Rnd) - 10)
Loop
rng.Value = iRandomize
Next rng
Range("B3:B8").NumberFormat = "0.00_ ;[Red]-0.00 "
End Sub
Code: "Farbbalken_im_Bereich"
Sub FarbBalken_im_Bereich()
With ActiveSheet
.Range("C3") = ("=B3")
.Range("C4") = ("=B4")
.Range("C5") = ("=B5")
.Range("C6") = ("=B6")
.Range("C7") = ("=B7")
.Range("C8") = ("=B8")
End With
Range("C3:C8").Select
Selection.FormatConditions.AddDatabar
Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = False 'Zellinhalt nicht zeigen
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueAutomaticMin
.MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
End With
With Selection.FormatConditions(1).BarColor
.Color = 5287936
End With
Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
Selection.FormatConditions(1).Direction = xlContext
Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
Selection.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic
With Selection.FormatConditions(1).NegativeBarFormat.Color
.Color = 255
End With
Range("A2").Select
End Sub
Anzeige