메인 컨텐츠로 가기

Excel에서 조회 값과 함께 배경색을 vlookup하고 반환하는 방법은 무엇입니까?

아래 스크린 샷과 같은 테이블이 있다고 가정합니다. 이제 지정된 값이 A 열에 있는지 확인한 다음 C 열의 배경색과 함께 해당 값을 반환하려고합니다. 어떻게 달성합니까? 이 기사의 방법은 문제를 해결하는 데 도움이 될 수 있습니다.

사용자 정의 함수에 의한 조회 값으로 Vlookup 및 반환 배경색


사용자 정의 함수에 의한 조회 값으로 Vlookup 및 반환 배경색

값을 조회하고 Excel에서 배경색과 함께 해당 값을 반환하려면 다음과 같이하십시오.

1. 조회 할 값이있는 워크 시트에서 시트 탭을 마우스 오른쪽 단추로 클릭하고 코드보기 상황에 맞는 메뉴에서. 스크린 샷보기 :

2. 오프닝에서 응용 프로그램 용 Microsoft Visual Basic 창에서 VBA 코드 아래를 코드 창에 복사하십시오.

VBA 코드 1 : Vlookup 및 조회 값으로 배경색 반환

Sub Worksheet_Change(ByVal Target As Range)
    Dim I As Long
    Dim xKeys As Long
    Dim xDicStr As String
    On Error Resume Next
    Application.ScreenUpdating = False
    xKeys = UBound(xDic.Keys)
    If xKeys >= 0 Then
        For I = 0 To UBound(xDic.Keys)
            xDicStr = xDic.Items(I)
            If xDicStr <> "" Then
                Range(xDic.Keys(I)).Interior.Color = _
                Range(xDic.Items(I)).Interior.Color
            Else
                Range(xDic.Keys(I)).Interior.Color = xlNone
            End If
        Next
        Set xDic = Nothing
    End If
    Application.ScreenUpdating = True
End Sub

3. 그런 다음 끼워 넣다 > 모듈, 아래 VBA 코드 2를 모듈 창에 복사하십시오.

VBA 코드 2 : Vlookup 및 조회 값으로 배경색 반환

Public xDic As New Dictionary
Function LookupKeepColor (ByRef FndValue, ByRef LookupRng As Range, ByRef xCol As Long)
    Dim xFindCell As Range
    On Error Resume Next
    Set xFindCell = LookupRng.Find(FndValue, , xlValues, xlWhole)
    If xFindCell Is Nothing Then
        LookupKeepColor = ""
        xDic.Add Application.Caller.Address, ""
    Else
        LookupKeepColor = xFindCell.Offset(0, xCol - 1).Value
        xDic.Add Application.Caller.Address, xFindCell.Offset(0, xCol - 1).Address
    End If
End Function

4. 두 개의 코드를 입력 후 도구 > 참고자료. 그런 다음 Microsoft 스크립트 런타임 상자에 참조 – VBAProject 대화 상자. 스크린 샷보기 :

5. 누르세요 다른 + Q 나가는 열쇠 응용 프로그램 용 Microsoft Visual Basic 창을 열고 워크 시트로 돌아갑니다.

6. 조회 값에 인접한 빈 셀을 선택한 다음 수식 입력 =LookupKeepColor(E2,$A$1:$C$8,3) 수식 입력 줄에 입력 한 다음 Enter 키를 누릅니다.

주의 사항: 공식에서 E2 조회할 값이 포함되어 있습니다. $ A $ 1 : $ C $ 8 테이블 범위 및 숫자 3 반환할 해당 값이 테이블의 세 번째 열에 있음을 의미합니다. 필요에 따라 변경하십시오.

7. 첫 번째 결과 셀을 계속 선택하고 채우기 핸들을 아래로 끌어 배경색과 함께 모든 결과를 가져옵니다. 스크린샷을 참조하십시오.


관련 기사 :

최고의 사무 생산성 도구

🤖 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 (34)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
This code is working fine , except in the cells that the formula is inputed in bring up 0 when the cell it is looking up is blank , my question is how do i make it ignore blank cells and prevent the cell the formula is in from inputting a 0 , is there some wheres in the code to enter an =IFERROR function maybe ?
This comment was minimized by the moderator on the site
Hi Kyle,

I tested this code and it does not bring up 0 when the cell it looks for is blank.
Perhaps you could include the formula in the IF function, as shown below, to prevent returning a result of 0.
=IF(B2="","",LookupKeepColor(E2,$A$1:$C$8,3))
This comment was minimized by the moderator on the site
Hi, Is this code working for office 2016 and later versions ?
This comment was minimized by the moderator on the site
no its not returning color.
This comment was minimized by the moderator on the site
I use times and dates from excel reports to create timesheets for our employees. If the specified date, for example, 2020/08/11 matches the date on the next tabs array (which contains many cells with the same date but different times) I want it to pull only the cell filled in orange which will be stated as 2020/08/11 7:45. Is this possible?
This comment was minimized by the moderator on the site
How I do
This comment was minimized by the moderator on the site
Hello, i have a sheet with 10,948 rows, its taking some time to pull the information with colors, still waiting. Is this normal, or there is something wrong?
This comment was minimized by the moderator on the site
This was AWESOME! followed the steps and it works beautifully! Thank you!
This comment was minimized by the moderator on the site
I have many records, it takes too long to process, and the code keeps on running even after completion. Please help
This comment was minimized by the moderator on the site
I have used this in Excel 2016 and only the data is transferred from Source to Target...….color is not transferred. Thoughts on what issue might be: Is it incompatibility with Excel 2016? Thanks. MT
This comment was minimized by the moderator on the site
i am getting the required cell color but i also need the lookup value as it is returning integer instead of string
This comment was minimized by the moderator on the site
Hi, Can i apply vlookup on color cells with no data in them
This comment was minimized by the moderator on the site
this works fine in office 2010, but not the 2013 version. Is there an update to the macro?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations