I looking for more efective solution for UserForm with many ComboBox's.
This is UserForm
obraz_2021-09-26_221536.png
Each of the Change Event of each ComboBox should copy date from Sheet ( with use fuction to get data) to first and secend TextBox; the third TextBox is for User to put data. So I have code for this (comment are in polish sorry) :
Private Sub ComBoxChag()
Dim X As Byte
Dim Y As Byte
For j = 1 To 24 ' Kopiuje dane do Arkusza
X = j * 3 - 2
Y = X + 1
z = j
If Controls("ComboBox" & j).Value = "" Then GoTo sprBlad Else: ' sprawdzamy kolejno czy jest wartość - brak koniec
Sheets("Arkusz1").Range("Kod_" & j) = Controls("ComboBox" & j) ' Wprowadzamy dane do arkusza; funkcje wytworzą dodatkowe dane (nazwe pozycji; jednostkę miary) patrz arkusz.
Controls("TextBox" & X).Value = Sheets("Arkusz1").Range("NazwaPoz" & j) ' zaciąga nazwe pozycji
Controls("TextBox" & Y).Value = Sheets("Arkusz1").Range("JednoMiary" & j) 'zaciągamy jednostkę miary
Next
GoTo Koniec:
sprBlad:
If z - 1 = 0 Then GoTo Koniec Else:
For i = 2 To 24
If Controls("ComboBox" & i).Value <> "" Then MsgBox ("Wypełnij pozycje kolejno, nie zostawiaj luk!")
Next
Koniec:
End Sub
I would like to run this program whenever one of ComboBox is change, but with not copy it to ever ComboBox1_Change; ComboBox2_Change ect.
Is ther any way to do this, or do you have other Idea.
Sorry For my english; is bit rusty
Bookmarks