اذهب الي المحتوي
أوفيسنا

اريد طريقة اضافة border للخلايا التي تحتوي على بيانات فقط


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

Sub BorderCells()
    Dim rng As Range
    Selection.Borders(xlEdgeLeft).LineStyle = 0
    Selection.Borders(xlEdgeTop).LineStyle = 0
    Selection.Borders(xlEdgeBottom).LineStyle = 0
    Selection.Borders(xlEdgeRight).LineStyle = 0
    Selection.Borders(xlInsideVertical).LineStyle = 0
    Selection.Borders(xlInsideHorizontal).LineStyle = 0
    For Each rng In Selection
        If Len(rng) <> 0 Then
            rng.Borders(xlEdgeLeft).LineStyle = 1
            rng.Borders(xlEdgeTop).LineStyle = 1
            rng.Borders(xlEdgeBottom).LineStyle = 1
            rng.Borders(xlEdgeRight).LineStyle = 1
        End If
    Next
End Sub

الكود يطبق علي الخلايا المحددة .. يمكن استبدال السليكشن بالنطاق المراد تطبيق الكود عليه

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

بعد اذن اخي عبد السلام

كود مختصر

Sub show_borders()
    With Selection.Borders
        .LineStyle = xlNone
        .LineStyle = xlContinuous
    End With
    
     With Selection.SpecialCells(xlCellTypeConstants, 23).Borders
      .LineStyle = xlContinuous
      .Weight = xlThin
    End With
    
End Sub

 

  • Like 3
رابط هذا التعليق
شارك

19 دقائق مضت, اشرف النعاس said:

كيف استخدم هذا الكود لنطاق معيد على سبيل المتال من A2 الى D10  في sheet 1

استبدل كلمة selection  باسم النطاق ليصبح الكود هكذا

Sub show_borders()
    With sheets("sheet1").Range("a2:d10").Borders
        .LineStyle = xlNone
        .LineStyle = xlContinuous
    End With
    
     With sheets("sheet1").Range("a2:d10").SpecialCells(xlCellTypeConstants, 23).Borders
      .LineStyle = xlContinuous
      .Weight = xlThin
    End With
    
End Sub

 

تم تعديل بواسطه سليم حاصبيا
رابط هذا التعليق
شارك

بعد اذن اخي سليم .. كود مختصر اكثر

Sub BorderCells()
    Selection.Borders.LineStyle = 0
    If Application.WorksheetFunction.CountA(Selection) = 0 Then Exit Sub
    Selection.SpecialCells(2, 23).Borders.LineStyle = 1
End Sub

 

رابط هذا التعليق
شارك

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.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information