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

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

قام بنشر

وعليكم السلام ورحمة الله وبركاته

تفضل
قبل فتح الملف 

اضغط بزر الفأرة يمين 

ثم اذهب للخصائص وحط صح على علامة التحذير

واضغط موافق

 

ولا تنس تفعيل الماكرو في اعدادات الاكسل حتى يعمل معك الزر

 

وهذا هو الكود المستخدم في الملف:
 

Sub MergeAndCenter()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    Dim lastRow As Long
    lastRow = ws.Cells(ws.Rows.Count, 3).End(xlUp).Row
    Dim startRow As Long, endRow As Long
    startRow = 1
    Dim i As Long

    Application.DisplayAlerts = False

    For i = 1 To lastRow
        If i = lastRow Or ws.Cells(i, 3).Value <> ws.Cells(i + 1, 3).Value Then
            endRow = i
            If endRow > startRow Then
                ws.Range(ws.Cells(startRow, 3), ws.Cells(endRow, 3)).Merge
                ws.Range(ws.Cells(startRow, 3), ws.Cells(endRow, 3)).HorizontalAlignment = xlCenter
            End If
            startRow = i + 1
        End If
    Next i

    Application.DisplayAlerts = True
End Sub

اختبار1.xlsm

  • Like 2
قام بنشر
Sub Test_Meragr_Celle()
'دمج
    Dim LastRow As Long
    Dim i As Long
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    With ActiveSheet
        LastRow = .Range("c" & .Rows.Count).End(xlUp).Row
        For i = LastRow To 2 Step -1
            If .Range("c" & i).Value = .Range("c" & i - 1).Value Then
                Application.Union(.Range("c" & i).MergeArea, .Range("c" & i - 1)).Merge
            End If
        Next i
    End With
    Application.DisplayAlerts = False
    Application.ScreenUpdating = True
End Sub
'*********************************
Sub annulation_Meragr_Celle()
' الغاء الدمج

    Dim Rng As Range, xCell As Range
    Set WorkRng = Range("c2:c" & Cells(Rows.Count, 3).End(xlUp).Row)
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
        For Each Rng In WorkRng
            If Rng.MergeCells Then
                With Rng.MergeArea
                    .UnMerge
                    .Formula = Rng.Formula
                End With
            End If
        Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

 

اختبار.xlsb

  • Like 4

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