اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

إذهب إلى أفضل إجابة Solved by محمد طاهر عرفه,

الردود الموصى بها

  • أفضل إجابة

اضافة محتوى القائمة المنسدلة آليا


السلام عليكم

I needed  to Autofill the validation dropdown list with specific values for a large number of cells

For a cell corresponding to Row B and Column C , I  wanted the drop down to show those values CCCC,CCC,CC,C,CB,B,BB,BBB,BBBB and so on for the rest of the matrix

The First step was to prepare the dropdown required contents using equations as shown on the table to the right side

السلام عليكم 

أردت ملء بيانات القائمة المنسدلة لعدد كبير من الخلايا ضمن مصفوفة

بحيث يكون متوى القائمة المنسدلة عند تقاطع العمود المعنون ب حرف C مع الصف المعنون بحرب B كالتالي

CCCC,CCC,CC,C,CB,B,BB,BBB,BBBB

و عليه فالخطوة الاولي قمت بتجهيز المحتوى المطلوب عن طريق المعادلات فى الجدول على اليمين كما هو مبين فى الصورة التالية

 

AutoFill_Droplist00.jpg.bc134842526fc2079ca4c8773275ba91.jpg

 

Next i prepare the following VBA code , which reads the values from the above table and add them to the dropdown list contents for all selection cells

The code reads the values 11 cells to the left ,of the target cell , and you can change that of course based on your case

و الخطوة التالية كانت اعداد الكود المطلوب لتنيذ العملية كما هو مبين أدناه

حيث يقوم الكود بقراءة المحتوى من الجدول اعلاه و اضافته ضمن القائمة المنسدلة لكل الخلايا فى الجدول على  اليمين

و الكود تم اعداده ليضف فى محتوى القائمة المنسدلة لكل خلية فى الجدول القيمة فى الخلية على بعد 11 عمود الي اليمين فى الجدول السابق، و طبعا يمكن تعديل هذه القسمة بحسب الجدول السابق

Sub FillDropDown()

Dim myrow As Byte, mycol As Byte, TargetVal As String

myrow = Selection.Rows.Count
mycol = Selection.Columns.Count
mycell = ActiveCell.AddressLocal

For i = 0 To myrow - 1
 For j = 0 To mycol - 1
 
   Range(mycell).Activate
   ActiveCell.Offset(i, j).Activate
   '11 is the number of cells the source value exist to the right of the target cell
   
   TargetVal = ActiveCell.Offset(0, 11).Value
    With ActiveCell.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=TargetVal
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    
    Next j
 Next i
       
End Sub

 

To run the code , add it in a module in your file , and make sure the file is saved as macro-enabled excel file

then select all the target cells in the left side table , Press Alt+F8 , then choose the code

قم باضافة الكود لملفك، و تأكد من حفظ الملف بصيغة تفعيل الماكرو  macro-enabled excel file

ثم قم باختبار كافة الخلايا المستهدفة 

اضغط ALT+F8

شغل الكود

AutoFill_Droplist01.jpg.28e7a65745782395a3bf1f2e11b50ba6.jpg

 

You will find that all cells in the target table has now the required dropdown list contents as targeted

ستجد أن كافة الخلايا التي تم اختيارها قتم تم اضافة قائمة منسدلة لها بالمحتوى المطلوب كما هو مبين فى الصورة

AutoFill_Droplist02.jpg.3077bf4e1d70acbf1fa2af06e3df7946.jpg

 

The Reason behind developing this code was that i needed to fill the dropdown lists in 225 cell with variable contents in this example related to using Analytic Hierarchy Process  (AHP)  technique to compute relative weights for any evaluation criteria 

ملاحظة: أضفت المحتوى باللغة الانجليزية ايضا لدراسة تأثير ذلك على انتشار المشاركة

كما يقولون الحاجة ام الاختراع ، فقط احتجت لهذا الأمر لملء 225 خلية بقوائم منسدلة ذات محتوى متغير فى هذا المثال الخاص بالأوزان النسبية لمعايير التقييم


 

  • Like 5
  • Thanks 1
رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • اضف...

Important Information