Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Textbox mit zufälliger Variable füttern

Empfohlene Antworten

Veröffentlicht

GuMo zusammen,

hab ein kleines Problem, das sich sicherlich einfach lösen lässt, aber irgendwie fehlt mir der Ansatz.

Ich habe mehrer Einträge in einer Exceltabelle, die ich nun in Zufälliger Reihenfolge in verschiedene Textboxen einlesen möchte. Doppelte Einträge dürfen nicht existieren, sprich jeder Wert aus der Exceltabelle darf nur einmal in einer Textbox auftauchen und in keiner weiteren.

Als Beispiel nehmen wir mal dies :

Sagen wir ich habe in der Exceltabelle 6 Namen, die 6 Namen sollen in der UserForm auf 6 Textboxen aufgeteilt werden und das Ganze in einer zufälligen Reihenfolge.

Oh, jetzt bin ich wohl zu spät dran. :beagolisc

Aber das hier hatte ich gerade fertig:


Const ANZVALUES = 6

Private Sub CommandButton1_Click()
Dim rowIndex%, colIndex%, index%, i%
Dim itemName$
Dim zufall%
Dim zArray(ANZVALUES) As Integer

rowIndex = 1 'Startzeile (bitte anpassen!)'
colIndex = 2 'Startreihe (bitte anpassen!)'
Randomize Timer

For i = 0 To ANZVALUES - 1
zArray(i) = -1 'Werte initialisieren'
Next i

For index = 0 To ANZVALUES - 1
Do
zufall = Rnd(1) * 5 'Zufallswerte 0 bis 5'
For i = 0 To ANZVALUES - 1
If zufall = zArray(i) Then
zufall = -1
Exit For
End If
Next i
Loop While zufall < 0
zArray(index) = zufall 'Zufallswert merken'

itemName = "TextBox" & index + 1
UserForm1.Controls.Item(itemName).Text = Tabelle1.Cells(rowIndex + zufall, colIndex)
Next index
End Sub
[/PHP]

vielleicht bringt's ja noch was...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.