Skip to main content

 Conas cealla a thrasuí i gcolún amháin bunaithe ar luachanna uathúla i gcolún eile?

Ag ceapadh, tá raon sonraí agat ina bhfuil dhá cholún, anois, ba mhaith leat cealla a thrasuí i gcolún amháin go sraitheanna cothrománacha bunaithe ar luachanna uathúla i gcolún eile chun an toradh seo a leanas a fháil. An bhfuil aon smaointe maithe agat chun an fhadhb seo a réiteach in Excel?

trasnaíonn doc luachanna uathúla 1

Trasuí cealla i gcolún amháin bunaithe ar luachanna uathúla le foirmlí

Trasuí cealla i gcolún amháin bunaithe ar luachanna uathúla le cód VBA

Trasuí cealla i gcolún amháin bunaithe ar luachanna uathúla le Kutools for Excel


Leis na foirmlí eagar seo a leanas, is féidir leat na luachanna uathúla a bhaint agus a gcuid sonraí comhfhreagracha a thrasuí i sraitheanna cothrománacha, déan mar a leanas le do thoil:

1. Iontráil an fhoirmle eagar seo: = INDEX ($ A $ 2: $ A $ 16, MATCH (0, COUNTIF ($ D $ 1: $ D1, $ A $ 2: $ A $ 16), 0)) isteach i gcill bhán, D2, mar shampla, agus brúigh Shift + Ctrl + Iontráil eochracha le chéile chun an toradh ceart a fháil, féach an scáileán:

trasnaíonn doc luachanna uathúla 2

nótaí: San fhoirmle thuas, A2: A16 an colún ar mhaith leat na luachanna uathúla a liostáil uaidh, agus D1 an cill os cionn na cille foirmle seo.

2. Ansin tarraing an láimhseáil líonta síos go dtí na cealla chun na luachanna uathúla uile a bhaint, féach an scáileán:

trasnaíonn doc luachanna uathúla 3

3. Agus ansin lean ar aghaidh leis an bhfoirmle seo a iontráil i gcill 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), agus cuimhnigh brú Shift + Ctrl + Iontráil eochracha chun an toradh a fháil, féach an scáileán:

trasnaíonn doc luachanna uathúla 4

nótaí: San fhoirmle thuas: B2: B16 an bhfuil na sonraí colúin is mian leat a thrasuí, A2: A16 an colún ar mhaith leat na luachanna a thrasuí bunaithe ar, agus D2 tá an luach uathúil atá bainte agat i gCéim 1.

4. Ansin tarraing an láimhseáil líonta ar thaobh na láimhe deise de na cealla ar mhaith leat na sonraí trasuite a liostáil go dtí taispeántais 0, féach an scáileán:

trasnaíonn doc luachanna uathúla 5

5. Agus ansin lean ort ag tarraingt an láimhseála líonta síos go dtí raon na gcealla chun na sonraí trasuite a fháil mar a thaispeántar an pictiúr a leanas:

trasnaíonn doc luachanna uathúla 6


B’fhéidir go bhfuil na foirmlí casta duit a thuiscint, anseo, is féidir leat an cód VBA seo a leanas a rith chun an toradh inmhianaithe a theastaíonn uait a fháil.

1. Coinnigh síos an ALT + F11 eochracha a oscailt Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Cliceáil Ionsáigh > Modúil, agus greamaigh an cód seo a leanas sa Modúil Fuinneog.

Cód VBA: Trasuí cealla i gcolún amháin bunaithe ar luachanna uathúla i gcolún eile:

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. Ansin brúigh F5 eochair chun an cód seo a rith, agus tiocfaidh bosca pras amach le cur i gcuimhne duit an raon sonraí a theastaíonn uait a úsáid a roghnú, féach an scáileán:

trasnaíonn doc luachanna uathúla 7

4. Agus ansin cliceáil OK cnaipe, popfaidh bosca pras eile amach le cur i gcuimhne duit cill a roghnú chun an toradh a chur, féach an scáileán:

trasnaíonn doc luachanna uathúla 8

6. Cliceáil OK cnaipe, agus rinneadh na sonraí i gcolún B a thrasuí bunaithe ar luachanna uathúla i gcolún A, féach an scáileán:

trasnaíonn doc luachanna uathúla 9


Má tá tú Kutools le haghaidh Excel, ag comhcheangal an Sraitheanna Comhcheangail Casta agus Cealla Scoilt fóntais, is féidir leat an tasc seo a chríochnú go tapa gan aon fhoirmlí ná cód.

Kutools le haghaidh Excel : le níos mó ná 300 breiseán áisiúil Excel, saor in aisce le triail gan aon teorannú i 30 lá.

Tar éis a shuiteáil Kutools le haghaidh Excel, déan mar a leanas le do thoil:

1. Roghnaigh an raon sonraí a theastaíonn uait a úsáid. (Más mian leat na sonraí bunaidh a choinneáil, déan na sonraí a chóipeáil agus a ghreamú go suíomh eile ar dtús.)

2. Ansin cliceáil Kutools > Cumaisc & Scoilt > Sraitheanna Comhcheangail Casta, féach ar an scáileán:

3. Sa an Comhcheangail Sraitheanna Bunaithe ar an gColún bosca dialóige, déan na hoibríochtaí seo a leanas le do thoil:

(1.) Cliceáil ainm an cholúin ar mhaith leat sonraí a thrasuí bunaithe air, agus roghnaigh Eochair Bhunscoile;

(2.) Cliceáil colún eile ar mhaith leat a thrasuí, agus cliceáil Chomhcheangail ansin roghnaigh deighilteoir amháin chun na sonraí comhcheangailte a scaradh, mar shampla spás, camóg, leathchlón.

trasnaíonn doc luachanna uathúla 11

4. Ansin cliceáil Ok cnaipe, tá na sonraí i gcolún B curtha le chéile i gcill amháin bunaithe ar cholún A, féach an scáileán:

trasnaíonn doc luachanna uathúla 12

5. Agus ansin roghnaigh na cealla comhcheangailte, agus cliceáil Kutools > Cumaisc & Scoilt > Cealla Scoilt, féach ar an scáileán:

6. Sa an Cealla Scoilt dialóg, roghnaigh Scoilt go Colúin faoi ​​na cineál rogha, agus ansin roghnaigh an deighilteoir a scarann ​​do chuid sonraí comhcheangailte, féach an scáileán:

trasnaíonn doc luachanna uathúla 14 14

7. Ansin cliceáil Ok cnaipe, agus roghnaigh cill chun an toradh scoilte a chur sa bhosca dialóige popped amach, féach an scáileán:

trasnaíonn doc luachanna uathúla 15

8. Cliceáil OK, agus gheobhaidh tú an toradh de réir mar is gá duit. Féach an pictiúr:

trasnaíonn doc luachanna uathúla 16

Íoslódáil agus triail saor in aisce Kutools le haghaidh Excel Now!


Kutools le haghaidh Excel: le níos mó ná 300 breiseán áisiúil Excel, saor in aisce le triail gan aon teorannú i 30 lá. Íoslódáil agus triail saor in aisce Anois!

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
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