انتقل إلى المحتوى الرئيسي

 كيفية تبديل الخلايا في عمود واحد بناءً على قيم فريدة في عمود آخر؟

لنفترض أن لديك نطاقًا من البيانات يحتوي على عمودين ، الآن ، تريد نقل الخلايا في عمود واحد إلى صفوف أفقية بناءً على قيم فريدة في عمود آخر للحصول على النتيجة التالية. هل لديك أي أفكار جيدة لحل هذه المشكلة في Excel؟

doc لنقل القيم الفريدة 1

تبديل الخلايا في عمود واحد استنادًا إلى قيم فريدة باستخدام الصيغ

تبديل الخلايا في عمود واحد استنادًا إلى القيم الفريدة برمز VBA

تبديل الخلايا في عمود واحد بناءً على قيم فريدة باستخدام Kutools for Excel


باستخدام صيغ الصفيف التالية ، يمكنك استخراج القيم الفريدة ونقل البيانات المقابلة لها إلى صفوف أفقية ، يرجى القيام بما يلي:

1. أدخل صيغة الصفيف هذه: = INDEX ($ A $ 2: $ A $ 16 ، MATCH (0 ، COUNTIF ($ D $ 1: $ D1 ، $ A $ 2: $ A $ 16) ، 0)) في خلية فارغة ، D2 ، على سبيل المثال ، واضغط على شيفت + كترل + إنتر مفاتيح معًا للحصول على النتيجة الصحيحة ، انظر لقطة الشاشة:

doc لنقل القيم الفريدة 2

ملاحظات: في الصيغة أعلاه ، A2: A16 هو العمود الذي تريد سرد القيم الفريدة منه ، و D1 هي الخلية الموجودة أعلى خلية الصيغة هذه.

2. ثم اسحب مقبض التعبئة لأسفل إلى الخلايا لاستخراج جميع القيم الفريدة ، انظر الصورة:

doc لنقل القيم الفريدة 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)، وتذكر أن تضغط شيفت + كترل + إنتر مفاتيح للحصول على النتيجة ، انظر الصورة:

doc لنقل القيم الفريدة 4

ملاحظات: في الصيغة أعلاه: B2: B16 هي بيانات العمود التي تريد نقلها ، A2: A16 هو العمود الذي تريد تبديل القيم بناءً عليه ، و D2 يحتوي على القيمة الفريدة التي قمت باستخراجها في الخطوة 1.

4. ثم اسحب مقبض التعبئة إلى يمين الخلايا التي تريد إدراج البيانات المنقولة حتى تعرض 0 ، انظر لقطة الشاشة:

doc لنقل القيم الفريدة 5

5. ثم استمر في سحب مقبض التعبئة لأسفل إلى نطاق الخلايا للحصول على البيانات المنقولة كما هو موضح في لقطة الشاشة التالية:

doc لنقل القيم الفريدة 6


قد تكون الصيغ معقدة لكي تفهمها ، هنا ، يمكنك تشغيل رمز VBA التالي للحصول على النتيجة المرجوة التي تحتاجها.

1. اضغط باستمرار على ALT + F11 مفاتيح لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. انقر إدراج > وحدة، والصق الكود التالي في ملف وحدة نافذة او شباك.

رمز فبا: تبديل الخلايا في عمود واحد استنادًا إلى قيم فريدة في عمود آخر:

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 مفتاح لتشغيل هذا الرمز ، وسيظهر مربع موجه لتذكيرك بتحديد نطاق البيانات الذي تريد استخدامه ، انظر لقطة الشاشة:

doc لنقل القيم الفريدة 7

4. ثم انقر فوق OK ، سيظهر مربع موجه آخر لتذكيرك بتحديد خلية لوضع النتيجة ، انظر لقطة الشاشة:

doc لنقل القيم الفريدة 8

6. انقر OK ، وتم تبديل البيانات الموجودة في العمود B بناءً على القيم الفريدة في العمود A ، انظر الصورة:

doc لنقل القيم الفريدة 9


إذا كان لديك كوتولس ل إكسيل، والجمع بين الجمع بين الصفوف المتقدمة و تقسيم الخلايا الأدوات المساعدة ، يمكنك إنهاء هذه المهمة بسرعة دون أي صيغ أو تعليمات برمجية.

كوتولس ل إكسيل : مع أكثر من 300 وظيفة إضافية مفيدة في Excel ، يمكنك تجربتها مجانًا دون قيود في أيام 30.

بعد تثبيت كوتولس ل إكسيليرجى القيام بما يلي:

1. حدد نطاق البيانات الذي تريد استخدامه. (إذا كنت تريد الاحتفاظ بالبيانات الأصلية ، فيرجى نسخ البيانات ولصقها في موقع آخر أولاً.)

2. ثم اضغط كوتولس > دمج وتقسيم > الجمع بين الصفوف المتقدمة، انظر لقطة الشاشة:

3. في ضم الصفوف على أساس العمود مربع الحوار ، يرجى القيام بالعمليات التالية:

(1.) انقر فوق اسم العمود الذي تريد تبديل البيانات بناءً عليه ، ثم حدد المفتاح الأساسي;

(2.) انقر فوق عمود آخر تريد تبديل موضعه ، وانقر فوق دمج ثم اختر فاصلًا واحدًا لفصل البيانات المدمجة ، مثل مسافة ، فاصلة ، فاصلة منقوطة.

doc لنقل القيم الفريدة 11

4. ثم اضغط Ok ، تم دمج البيانات الموجودة في العمود B معًا في خلية واحدة استنادًا إلى العمود A ، انظر الصورة:

doc لنقل القيم الفريدة 12

5. ثم حدد الخلايا المدمجة ، وانقر فوق كوتولس > دمج وتقسيم > تقسيم الخلايا، انظر لقطة الشاشة:

6. في تقسيم الخلايا مربع الحوار، حدد انقسام إلى أعمدة تحت النوع الخيار ، ثم اختر الفاصل الذي يفصل بين بياناتك المدمجة ، انظر الصورة:

doc تبديل القيم الفريدة 14 14

7. ثم اضغط Ok ، وحدد خلية لوضع نتيجة الانقسام في مربع الحوار المنبثق ، انظر لقطة الشاشة:

doc لنقل القيم الفريدة 15

8. انقر OK، وستحصل على النتيجة التي تريدها. انظر لقطة الشاشة:

doc لنقل القيم الفريدة 16

قم بتنزيل Kutools for Excel والإصدار التجريبي المجاني الآن!


كوتولس ل إكسيل: مع أكثر من 300 وظيفة إضافية مفيدة في Excel ، يمكنك تجربتها مجانًا دون قيود خلال 30 يومًا. تنزيل وتجربة مجانية الآن!

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 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