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

 كيفية تحديد عمود بناءً على رأس العمود في Excel؟

لنفترض أن لديك ورقة عمل كبيرة تحتوي على أعمدة متعددة ، والآن تريد تحديد العمود المحدد بناءً على اسم رأس العمود. للعثور على عمود بعمود في ورقة عمل كبيرة سيضيع الكثير من الوقت ، هذه المقالة ، سأقدم طريقة سريعة لحل هذه المهمة في Excel.

حدد عمودًا بناءً على اسم رأس العمود برمز VBA


حدد عمودًا بناءً على اسم رأس العمود برمز VBA

يمكن أن يساعدك رمز VBA التالي في تحديد الأعمدة بناءً على اسم رأس محدد ، يرجى القيام بذلك على النحو التالي:

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

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

رمز فبا: حدد العمود بناءً على اسم رأس العمود:

Sub FindAddressColumn()
'Updateby Extendoffcie
    Dim xRg As Range
    Dim xRgUni As Range
    Dim xFirstAddress As String
    Dim xStr As String
    On Error Resume Next
    xStr = "Name"
    Set xRg = Range("A1:P1").Find(xStr, , xlValues, xlWhole, , , True)
    If Not xRg Is Nothing Then
        xFirstAddress = xRg.Address
        Do
            Set xRg = Range("A1:P1").FindNext(xRg)
            If xRgUni Is Nothing Then
                Set xRgUni = xRg
            Else
                Set xRgUni = Application.Union(xRgUni, xRg)
            End If
        Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
    End If
    xRgUni.EntireColumn.Select
End Sub

ملاحظات: في الكود أعلاه ، A1: P1 هو نطاق الرؤوس التي تريد تحديد الأعمدة منها ، و "الاسم"في البرنامج النصي xStr = "الاسم" هو اسم الرأس الذي تريد تحديد الأعمدة بناءً عليه. يرجى تغييرها حسب حاجتك.

3. بعد نسخ ولصق الرمز ، يرجى الضغط على F5 المفتاح لتشغيل هذا الرمز ، وتم تحديد جميع الأعمدة التي تحمل اسم الرأس المحدد مرة واحدة ، انظر الصورة:

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

🤖 مساعد 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Good job, works great!
This comment was minimized by the moderator on the site
Hi everyone...

How can I make it so that only the column data is selected, without the header, instead of the entire column?

Thanks
This comment was minimized by the moderator on the site
Thank you spo much saved my day !
This comment was minimized by the moderator on the site
Thanks - at first it seemed to work, but then I noticed it didn't include the first-found column - it started with the second and on.

Which is explainable: you set xRg twice, but you do not include the first one.

TBH: initially I thought it worked fine, but then that 'error' showed up and I had to figure out why....

I fixed it as follows: (in Excel the comments will turn green and show my edits: '***)

<code>

Sub FindAddressColumn()

'Updateby Extendoffcie

Dim xRg As Range

Dim xRgUni As Range

Dim xFirstAddress As String

Dim xStr As String

On Error Resume Next
xStr = "Name"
Set xRg = Range("A1:P1").Find(xStr, , xlValues, xlPart, , , True)

If Not xRg Is Nothing Then

xFirstAddress = xRg.Address

Do

If xRgUni Is Nothing Then

Set xRgUni = Range(xFirstAddress) '*** Using the first-found range

Else

Set xRgUni = Application.Union(xRgUni, xRg)

End If



Set xRg = Range("A1:P1").FindNext(xRg) '*** Now searching for the second/next ones



Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)

End If

xRgUni.EntireColumn.Select

End Sub


</code>

This now works for me, but I hope to learn from you if I overlooked anything.
This comment was minimized by the moderator on the site
Hi, Can you suggest the macro for the issue mentioned below by Shaun
This comment was minimized by the moderator on the site
Hi, looks great work. But I am getting the compile error: Argument not optional while highlighting the ". Union". What should I do?
This comment was minimized by the moderator on the site
This is great, but what if I wanted to copy say, CustomerName, OrderNumber, OrderDate, FulfillmentDate, OrderStatus from Sheet1 with many more columns.
How do I only specify the columns that are needed to be copied to another sheet? This seems to only specify one column.
I have tried some things, but the problem is more where the columns are not necesarily in the same order on the source sheet. The source data in Sheet1 is pasted from the Windows clipboard to the Excel sheet.

It may be, CustomerName, OrderDate, OrderNumber, OrderStatusm FulfillmentDate or some other order.

I need them to be copied into a new sheet in a specific order as there are formulas in Sheet2 that are applied to what is copied from Sheet1 to Sheet2.

Other than shifting columns around after pasting from Windows clipboard, I can't figure this out.

Please help if possible.

Thank you kindly for the above though.
This comment was minimized by the moderator on the site
Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xStr As String

Are variables being declared.

Hence to use the above code again for another column you would have to declare new variables.

Dim xRg2 As Range
Dim xRgUni2 As Range
Dim xFirstAddress2 As String
Dim xStr2 As String

And replace every instance of xRg with xRg2 in the code ect. Does that make sense?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations