Skip i'r prif gynnwys

Sut i boblogi blwch testun yn seiliedig ar ddetholiad combobox ar UserForm yn Excel?

Gan dybio bod gennych dabl yn cynnwys Enw a cholofn rhif Staff fel y dangosir isod. Nawr mae angen i chi greu Ffurflen Ddefnyddiwr wedi'i hymgorffori â blwch combo sy'n casglu'r holl enwau y tu mewn a blwch testun a fydd yn poblogi'r rhif staff cyfatebol wrth ddewis enw o'r blwch combo. Gall y dull yn yr erthygl hon eich helpu i'w ostwng.

Blwch testun poblog yn seiliedig ar ddetholiad combobox ar Userform gyda VBA


Blwch testun poblog yn seiliedig ar ddetholiad combobox ar Userform gyda VBA

Gwnewch fel a ganlyn i boblogi blwch testun â gwerth cyfatebol yn seiliedig ar ddetholiad combobox ar Userform.

1. Gwasgwch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch Mewnosod > Ffurflen ddefnyddiwr. Gweler y screenshot:

3. Yna mewnosodwch reolaeth blwch Combo a rheolydd blwch Testun yn y Ffurflen Ddefnyddiwr a grëwyd fel y dangosir isod.

4. De-gliciwch ar unrhyw le gwag yn y Ffurflen Ddefnyddiwr, ac yna cliciwch Gweld y Cod o'r ddewislen cyd-destun. Gweler y screenshot:

5. Yn y ffenestr Userform (Cod) agoriadol, copïwch a gludwch y cod VBA isod i ddisodli'r gwreiddiol.

Cod VBA: Poblogaeth blwch testun yn seiliedig ar ddetholiad combobox ar Userform

Dim xRg As Range
'Updated by Extendoffice 2018/1/30
Private Sub UserForm_Initialize()
    Set xRg = Worksheets("Sheet5").Range("A2:B8")
    Me.ComboBox1.List = xRg.Columns(1).Value
End Sub
Private Sub ComboBox1_Change()
    Me.TextBox1.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 2, False)
End Sub

Nodyn: Yn y cod, A2: B2 yw'r amrediad sy'n cynnwys y gwerthoedd y byddwch chi'n eu poblogi ar wahân yn y blwch combo Userform a'r blwch testun. A Sheet5 yw enw'r daflen waith sy'n cynnwys yr ystod ddata. Newidiwch nhw yn ôl yr angen.

6. Gwasgwch y Alt + Q allweddi i adael y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

7. Cliciwch Datblygwr > Mewnosod > Botwm Gorchymyn (Rheoli ActiveX) i fewnosod botwm gorchymyn yn y daflen waith.

8. De-gliciwch y tab dalen a dewis Gweld y Cod o'r ddewislen clicio ar y dde. Yna copïwch a gludwch god VBA i mewn i'r ffenestr cod.

Cod VBA: Dangos ffurf defnyddiwr

Private Sub CommandButton1_Click()
'Updated by Extendoffice 2018/1/30
    UserForm1.Show
End Sub

9. Diffoddwch y Modd Dylunio yn y llyfr gwaith.

Cliciwch y botwm gorchymyn i agor y ffurf defnyddiwr benodol. Yna gallwch weld bod yr holl enwau'n cael eu casglu yn y blwch combo. Wrth ddewis enw o'r blwch combo, bydd y rhif staff cyfatebol yn cael ei boblogi i'r blwch testun yn awtomatig fel islaw'r screenshot a ddangosir.


Erthyglau cysylltiedig:

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
can the same be don on excel sheet? instead of userform? i am using sheet not userform
This comment was minimized by the moderator on the site
alguem poderia me ajudar estou tentando carregar a combobox e puxar informações para text box so que esta dando erro 381

Private Sub ComboNome_Emissor_Change()
TextArea.Text = ComboNome_Emissor.List(ComboNome_Emissor.ListIndex, 1)
TextTreinamento_PT.Text = ComboNome_Emissor.List(ComboNome_Emissor.ListIndex, 3)
TextTreinamento_EC.Text = ComboNome_Emissor.List(ComboNome_Emissor.ListIndex, 5)
TexStatus_Bloqueio.Text = ComboNome_Emissor.List(ComboNome_Emissor.ListIndex, 6)


End Sub
This comment was minimized by the moderator on the site
The method is very simple and populates the combo box quite efficiently. However, when I try populating the text box, I get a run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class. Kindly assist with resolving this error.
This comment was minimized by the moderator on the site
I just tried this code and was running into the same issue. I realized I had the xRg variable inside the UserForm block, so it was not being accessed by my ComboBox function. Maybe others are running into the same issue
This comment was minimized by the moderator on the site
Hi,
May I have your Office version? I need the feedback to check for the error.
Thanks for your comment.
This comment was minimized by the moderator on the site
office 2010 32 bit
This comment was minimized by the moderator on the site
Good day,
I have tried the code in Office 2010 32 bit, but no errors occured.
Please make sure the sheet name and cell range in the first VBA code are the same with your actual sheet name and range.
Thanks for your comment.
This comment was minimized by the moderator on the site
Hi,
i have same issue with office 2013. Any solution please
This comment was minimized by the moderator on the site
i have the same problem....
This comment was minimized by the moderator on the site
I too have the same problem
This comment was minimized by the moderator on the site
Hi Chaylon,
Have you replaced the sheet name in the below code line with your actual used worksheet name?
Set xRg = Worksheets("Sheet5").Range("A2:B8")
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations