메인 컨텐츠로 가기

 다른 열의 고유 값을 기반으로 한 열의 셀을 바꾸는 방법은 무엇입니까?

두 개의 열을 포함하는 데이터 범위가 있다고 가정하면 다음 결과를 얻기 위해 한 열의 셀을 다른 열의 고유 값을 기반으로 가로 행으로 바꾸려고합니다. Excel에서이 문제를 해결할 좋은 아이디어가 있습니까?

문서 고유 값 전치 1

수식을 사용하여 고유 한 값을 기반으로 한 열의 셀 전치

VBA 코드로 고유 값을 기반으로 한 열의 셀 전치

Excel 용 Kutools를 사용하여 고유 값을 기반으로 한 열의 셀 전치


다음 배열 수식을 사용하여 고유 한 값을 추출하고 해당 데이터를 가로 행으로 전치 할 수 있습니다. 다음과 같이하십시오.

1. 다음 배열 수식을 입력하십시오. = INDEX ($ A $ 2 : $ A $ 16, MATCH (0, COUNTIF ($ D $ 1 : $ D1, $ A $ 2 : $ A $ 16), 0)) 예를 들어 빈 셀 D2에 넣고 쉬프트 + 컨트롤 + 엔터 키를 함께 사용하여 올바른 결과를 얻으려면 스크린 샷을 참조하십시오.

문서 고유 값 전치 2

주의 사항: 위의 공식에서 A2 : A16 고유 값을 나열하려는 열입니다. D1 이 수식 셀 위에있는 셀입니다.

2. 그런 다음 채우기 핸들을 셀로 끌어 모든 고유 값을 추출합니다. 스크린 샷을 참조하십시오.

문서 고유 값 전치 3

3. 그런 다음이 수식을 E2 셀에 입력합니다. =IFERROR(INDEX($B$2:$B$16, MATCH(0, COUNTIF($D2:D2,$B$2:$B$16)+IF($A$2:$A$16<>$D2, 1, 0), 0)), 0)을 누르고 쉬프트 + 컨트롤 + 엔터 결과를 얻으려면 키, 스크린 샷 참조 :

문서 고유 값 전치 4

주의 사항: 위 공식에서 : B2 : B16 전치하려는 열 데이터입니다. A2 : A16 값을 전치하려는 열입니다. D2 1 단계에서 추출한 고유 한 값을 포함합니다.

4. 그런 다음 0이 표시 될 때까지 전치 된 데이터를 나열하려는 셀의 오른쪽으로 채우기 핸들을 끕니다 (스크린 샷 참조).

문서 고유 값 전치 5

5. 그런 다음 채우기 핸들을 셀 범위까지 계속 드래그하여 다음 스크린 샷과 같이 전치 된 데이터를 가져옵니다.

문서 고유 값 전치 6


수식이 이해하기 복잡 할 수 있습니다. 여기에서 다음 VBA 코드를 실행하여 필요한 결과를 얻을 수 있습니다.

1. 누르고 ALT + F11 키를 눌러 응용 프로그램 용 Microsoft Visual Basic 창.

2. 딸깍 하는 소리 끼워 넣다 > 모듈을 클릭하고 다음 코드를 모듈 창문.

VBA 코드 : 다른 열의 고유 한 값을 기반으로 한 열의 셀 전치 :

Sub transposeunique()
'updateby Extendoffice
    Dim xLRow As Long
    Dim i As Long
    Dim xCrit As String
    Dim xCol  As New Collection
    Dim xRg As Range
    Dim xOutRg As Range
    Dim xTxt As String
    Dim xCount As Long
    Dim xVRg As Range
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("please select data range(only two columns):", "Kutools for Excel", xTxt, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
    If (xRg.Columns.Count <> 2) Or _
       (xRg.Areas.Count > 1) Then
        MsgBox "the used range is only one area with two columns ", , "Kutools for Excel"
        Exit Sub
    End If
    Set xOutRg = Application.InputBox("please select output range(specify one cell):", "Kutools for Excel", xTxt, , , , , 8)
    If xOutRg Is Nothing Then Exit Sub
    Set xOutRg = xOutRg.Range(1)
    xLRow = xRg.Rows.Count
    For i = 2 To xLRow
        xCol.Add xRg.Cells(i, 1).Value, xRg.Cells(i, 1).Value
    Next
    Application.ScreenUpdating = False
    For i = 1 To xCol.Count
        xCrit = xCol.Item(i)
        xOutRg.Offset(i, 0) = xCrit
        xRg.AutoFilter Field:=1, Criteria1:=xCrit
        Set xVRg = xRg.Range("B2:B" & xLRow).SpecialCells(xlCellTypeVisible)
        If xVRg.Count > xCount Then xCount = xVRg.Count
        xRg.Range("B2:B" & xLRow).SpecialCells(xlCellTypeVisible).Copy
        xOutRg.Offset(i, 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
        Application.CutCopyMode = False
    Next
    xOutRg = xRg.Cells(1, 1)
    xOutRg.Offset(0, 1).Resize(1, xCount) = xRg.Cells(1, 2)
    xRg.Rows(1).Copy
    xOutRg.Resize(1, xCount + 1).PasteSpecial Paste:=xlPasteFormats
    xRg.AutoFilter
    Application.ScreenUpdating = True
End Sub

3. 그런 다음 F5 키를 눌러이 코드를 실행하면 사용할 데이터 범위를 선택하라는 메시지 상자가 나타납니다. 스크린 샷을 참조하십시오.

문서 고유 값 전치 7

4. 그런 다음 OK 버튼을 누르면 결과를 넣을 셀을 선택하라는 메시지가 표시되는 또 다른 프롬프트 상자가 나타납니다. 스크린 샷을 참조하십시오.

문서 고유 값 전치 8

6. 딸깍 하는 소리 OK 버튼을 클릭하고 B 열의 데이터가 A 열의 고유 한 값을 기반으로 전치되었습니다. 스크린 샷 참조 :

문서 고유 값 전치 9


당신이 있으면 Excel 용 Kutools, 결합 고급 결합 행셀 분할 유틸리티를 사용하면 수식이나 코드없이이 작업을 빠르게 완료 할 수 있습니다.

Excel 용 Kutools : 300 개 이상의 편리한 Excel 추가 기능으로 30 일 동안 제한없이 무료로 사용해 볼 수 있습니다..

설치 후 Excel 용 Kutools, 다음과 같이하십시오.

1. 사용할 데이터 범위를 선택하십시오. (원래 데이터를 유지하려면 먼저 데이터를 복사하여 다른 위치에 붙여 넣으십시오.)

2. 그런 다음 쿠툴 > 병합 및 분할 > 고급 결합 행, 스크린 샷 참조 :

3. 에서 열을 기준으로 행 결합 대화 상자에서 다음 작업을 수행하십시오.

(1.) 데이터를 전치하려는 열 이름을 클릭하고 기본 키;

(2.) 전치하려는 다른 열을 클릭하고 결합 그런 다음 하나의 구분 기호를 선택하여 공백, 쉼표, 세미콜론과 같은 결합 된 데이터를 구분합니다.

문서 고유 값 전치 11

4. 그런 다음 Ok 버튼을 클릭하면 B 열의 데이터가 A 열을 기준으로 하나의 셀에 결합되었습니다. 스크린 샷 참조 :

문서 고유 값 전치 12

5. 그런 다음 결합 된 셀을 선택하고 쿠툴 > 병합 및 분할 > 셀 분할, 스크린 샷 참조 :

6. 에서 셀 분할 대화 상자에서 열로 분할 아래 타입 옵션을 선택한 다음 결합 된 데이터를 구분하는 구분 기호를 선택합니다. 스크린 샷을 참조하십시오.

문서 고유 값 전치 14 14

7. 그런 다음 Ok 버튼을 클릭하고 튀어 나온 대화 상자에 분할 결과를 넣을 셀을 선택합니다. 스크린 샷 참조 :

문서 고유 값 전치 15

8. 딸깍 하는 소리 OK, 필요한 결과를 얻을 수 있습니다. 스크린 샷보기 :

문서 고유 값 전치 16

Excel 용 Kutools를 지금 다운로드하고 무료로 평가하십시오!


Excel 용 Kutools: 300 개 이상의 편리한 Excel 추가 기능으로 30 일 동안 제한없이 무료로 사용해 볼 수 있습니다. 지금 다운로드 및 무료 평가판!

최고의 사무 생산성 도구

🤖 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 (56)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Like many people in the below my column "b" has duplicates I still want to appear in a column, I.e. 
How to do the transpose if B column doesn't have unique values but still need those values
KTE 100
KTE 100

Can you shared a modified equation that works in that scenario? I appears lots of people have this question below without an answer.
Thank you, 
This comment was minimized by the moderator on the site
have you solve the problem?
This comment was minimized by the moderator on the site
Hello, Alicia,If there are duplicate values in the second column, you should apply the below array formula:=IFERROR(INDEX($B$2:$B$16,SMALL(IF($D2=$A$2:$A$16,ROW($A$2:$A$16)-ROW($A$2)+1),COLUMN(A1))),"")
After inserting the formula, please remember to press Shift + Ctrl + Enter keys.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
how would you do the first order but with multiple columns of data for each product? Like if KTO and KTE had multiple pieces of data in columns C, D, E,...

This was the formula used:

=IFERROR(INDEX($B$2:$B$16, MATCH(0, COUNTIF($D2:D2,$B$2:$B$16)+IF($A$2:$A$16<>$D2, 1, 0), 0)), 0)
This comment was minimized by the moderator on the site
thanks !! just what i was looking for !! works as intended !!
This comment was minimized by the moderator on the site
this was a very, very helpful post - thank you!
I found the VBA version did not yield the expected results at least when running in VBA 7.1 (Excel for Office 365 - 16.0.x - 64-bit). I tweaked it a bit to get the results I wanted:


Sub transposeunique()

'updateby Extendoffice

'updateby skipow June 2020

Dim xLRow As Long

Dim i As Long

Dim xCrit As String

Dim xCritLast As String

Dim xCol As New Collection

Dim xRg As Range

Dim xOutRg As Range

Dim xTxt As String

Dim xCount As Long

Dim xVRg As Range

On Error Resume Next

xTxt = ActiveWindow.RangeSelection.Address

Set xRg = Application.InputBox("please select data range(only two columns):", "Kutools for Excel", xTxt, , , , , 8)

Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)

If xRg Is Nothing Then Exit Sub

If (xRg.Columns.Count <> 2) Or _

(xRg.Areas.Count > 1) Then

MsgBox "the used range is only one area with two columns ", , "Kutools for Excel"

Exit Sub

End If

Set xOutRg = Application.InputBox("please select output range(specify one cell):", "Kutools for Excel", xTxt, , , , , 8)

If xOutRg Is Nothing Then Exit Sub

Set xOutRg = xOutRg.Range(1)

xLRow = xRg.Rows.Count

For i = 2 To xLRow

'xCol.Add xRg.Cells(i, 1).Value, xRg.Cells(i, 1).Value

'the above line commented out - the Add function to the Collection (at least in VBA 7.1) doesn't accept this format

xCol.Add Item:=xRg.Cells(i, 1).Value

'you only need the first column put into the Collection



Next

Application.ScreenUpdating = False

For i = 1 To xCol.Count

xCrit = xCol.Item(i)

'if you don't keep track of the last entry and compare to the next entry you'll get duplicate lines

If xCrit = xCritLast Then

xRg.AutoFilter

Else

xOutRg.Offset(i, 0) = xCrit

xRg.AutoFilter Field:=1, Criteria1:=xCrit

Set xVRg = xRg.Range("B2:B" & xLRow).SpecialCells(xlCellTypeVisible)

If xVRg.Count > xCount Then xCount = xVRg.Count

xRg.Range("B2:B" & xLRow).SpecialCells(xlCellTypeVisible).Copy

xOutRg.Offset(i, 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True

Application.CutCopyMode = False

'save the last entry and compare above to the next one to avoid duplicates

xCritLast = xCrit

End If

Next

xOutRg = xRg.Cells(1, 1)

xOutRg.Offset(0, 1).Resize(1, xCount) = xRg.Cells(1, 2)

xRg.Rows(1).Copy

xOutRg.Resize(1, xCount + 1).PasteSpecial Paste:=xlPasteFormats

xRg.AutoFilter

Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
This works, but it gives me duplicates. Is there a way to make it not?
This comment was minimized by the moderator on the site
it worked for me, i had to sort the first column though
This comment was minimized by the moderator on the site
can you please share the code if there are 2 columns to be copied instead of 1. below is the example.
This comment was minimized by the moderator on the site
I have a data set which has 3 columns presented below:



Column A Column B Column C



Country1 Year1 Value1

Country1 Year2 Value2

Country1 Year3 Value3,



Country2 Year1 Value1

Country2 Year3 Value3,

...........



I need to combine these 3 columns in a table like this:

Year1 Year2 Year3 ................................. YearX



Country1 Value1 Value2 Value3

Country2 Value1 #Missing Value3

.....
.....
.....

CountryX Valuex ..................





The problem i am facing is that for some data in column A i don't have values for each year only for some.(For example country 2 has missing values for Year 2)





Is there a way to work around this issue and resolve it?



Thank you in advance!
This comment was minimized by the moderator on the site
I have a data set which has multiple IDs in column A, and has connected data in column B. I used the above formula and altered it a bit so that I am transposing the cells in the column B into a row based on the unique ID tied to it in column A. The formula used to identify the unique IDs is: =INDEX($A$2:$A$13409, MATCH(0, COUNTIF($D$1:$D1, $A$2:$A$13409), 0)). The formula used to do the transposing is: =IFERROR(INDEX($B$2:$B$13409, MATCH(0, IF($A$2:$A$13409<>$D2, 1, 0)+COUNTIF($D2:D2,$B$2:$B$13409), 0)), "N/A"). Both given in the article, only slightly altered.

The issue is my data set in column B has duplicates, sometimes appearing one after another, and I need all of the values in the column to be presented in the rows.

The image attached is what I would like the table to show (this is a small sample size, the true dataset has over 13,000 entries). What is happening now is when a repeat value is encountered, it will not count it.
i.e. Row 9 for ID 11980 now only shows 0 -31.79 -0.19 -0.74 N/A N/A .... when what I need it to show instead is 0 0 -31.79 -0.19 -0.74 0 0 N/A N/A ....

Is there a way to work around this issue and resolve it?

Thank you in advance!
This comment was minimized by the moderator on the site
Did you ever get a response/resolution to this challenge? I have the same one.
This comment was minimized by the moderator on the site
I have a data set in Columns A (Unique ID) - E. Each row has data based on the ID#, there are multiple rows for each ID# but I want one row per ID# with all of the other data in columns (it would be 5 columns long minimum and 25 maximum depending on how many each unique ID has). I found a code but it only works for two columns. I had to concatenate the four columns (not including ID) then delimit after running the macro (lot of work). For 15,000 rows of data this is extra time consuming. Is there an endless column macro that would work? Thanks in advance everyone for your help!
ID CODE ST CODE# DATE
This comment was minimized by the moderator on the site
The macro did not work. It just copied the contents in cell A1.
This comment was minimized by the moderator on the site
=INDEX($A$2:$A$16, MATCH(0, COUNTIF($D$1:$D1, $A$2:$A$16), 0)) worked for me to transpose the unique values of A column into a new column BUT...is there a way to get the all the values in B column to be transposed as given below:

Product Order Date Product Order Order Order Order Order Order Order
KTE 100 3/3/2019 KTE 100 100 100 200 100 150 100
KTO 150 3/3/2019 KTO 150 100 200 100 150 200
KTE 100 3/4/2019 BOT 150 100 200 150 100 200
KTO 100 3/4/2019 COD 200 150 100 150
KTO 200 3/5/2019
KTE 100 3/5/2019
BOT 150 3/5/2019
BOT 100 3/6/2019
KTO 100 3/6/2019
KTE 200 3/6/2019
BOT 200 3/7/2019
COD 200 3/7/2019
KTE 100 3/7/2019
KTO 150 3/7/2019
BOT 150 3/8/2019
KTE 150 3/8/2019
COD 150 3/8/2019
BOT 100 3/9/2019
BOT 200 3/10/2019
COD 100 3/10/2019
KTO 200 3/10/2019
COD 150 3/11/2019
KTE 100 3/11/2019
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