메인 컨텐츠로 가기

Excel의 사용자 양식에서 콤보 상자 선택을 기반으로 텍스트 상자를 채우는 방법은 무엇입니까?

아래 스크린 샷과 같이 테이블에 이름과 직원 번호 열이 있다고 가정합니다. 이제 내부에 모든 이름을 수집하는 콤보 상자와 콤보 상자에서 이름을 선택할 때 해당 직원 번호를 채울 텍스트 상자가 포함 된 사용자 양식을 만들어야합니다. 이 기사의 방법은 당신이 그것을 내리는 데 도움이 될 수 있습니다.

VBA를 사용하여 사용자 양식에서 콤보 상자 선택을 기반으로 텍스트 상자 채우기


VBA를 사용하여 사용자 양식에서 콤보 상자 선택을 기반으로 텍스트 상자 채우기

Userform의 콤보 상자 선택에 따라 텍스트 상자를 해당 값으로 채우려면 다음과 같이하십시오.

1. 누르세요 다른 + F11 키를 눌러 응용 프로그램 용 Microsoft Visual Basic 창.

2. 에서 응용 프로그램 용 Microsoft Visual Basic 창을 클릭합니다 끼워 넣다 > 사용자 양식. 스크린 샷보기 :

3. 그런 다음 아래 스크린 샷과 같이 생성 된 Userform에 콤보 상자 컨트롤과 텍스트 상자 컨트롤을 삽입합니다.

4. 사용자 양식의 빈 공간을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 상황에 맞는 메뉴에서. 스크린 샷보기 :

5. 여는 사용자 양식 (코드) 창에서 아래 VBA 코드를 복사하여 붙여 넣어 원본을 대체하십시오.

VBA 코드 : 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

주의 사항: 코드에서 A2:B2는 사용자 양식 콤보 상자와 텍스트 상자 모두에 별도로 채울 값이 포함된 범위입니다. 그리고 Sheet5는 데이터 범위가 포함된 워크시트의 이름입니다. 필요에 따라 변경하십시오.

6. 누르세요 다른 + Q 나가는 열쇠 응용 프로그램 용 Microsoft Visual Basic 창.

7. 클릭 개발자 > 끼워 넣다 > 명령 단추 (ActiveX 컨트롤) 워크 시트에 명령 단추를 삽입합니다.

8. 시트 탭을 마우스 오른쪽 버튼으로 클릭하고 코드보기 마우스 오른쪽 버튼 클릭 메뉴에서 그런 다음 VBA 코드를 복사하여 코드 창에 붙여넣습니다.

VBA 코드: 사용자 양식 표시

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

9. 통합 문서에서 디자인 모드를 끕니다.

지정된 사용자 양식을 열려면 명령 단추를 클릭하십시오. 그러면 모든 이름이 콤보 상자에 수집되는 것을 볼 수 있습니다. 콤보 상자에서 이름을 선택하면 해당 직원 번호가 아래 표시된 스크린샷과 같이 텍스트 상자에 자동으로 채워집니다.


관련 기사 :

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
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