Combinar celdas dependiendo del valor de otras columnas

Necesito una macro vba para combinar celdas, pero las celdas no sólo deben ser iguales en la columna a combinar, si no que en la columna anterior los valores que se corresponden a esas celdas también deben ser iguales.

ADGL                            BELVER S.L.

ADGL                            BELVER S.L.

ADGL                            BELVER S.L.

CONFID                        BELVER S.L.                      

CONFID                        BELVER S.L.              

Debería quedar

ADGL                            BELVER  S.L.

CONFID                        BELVER S.L.   

Respuesta
1

Te anexo la macro, solamente cambia el 2 por el número de fila donde inician tus datos.

Sub Cobinar_Celdas()
'Por Dante Amor
    '
    Application.DisplayAlerts = False
    ini = 2    'fila inicial de datos
    '
    an1 = Cells(ini, "A").Value
    an2 = Cells(ini, "B").Value
    For i = ini To Range("A" & Rows.Count).End(xlUp).Row + 1
        If Not (Cells(i, "A").Value = an1 And Cells(i, "B").Value = an2) Then
            Range(Cells(ini, "A"), Cells(fin, "B")).HorizontalAlignment = xlCenter
            Range(Cells(ini, "A"), Cells(fin, "B")).VerticalAlignment = xlCenter
            Range(Cells(ini, "A"), Cells(fin, "A")).MergeCells = True
            Range(Cells(ini, "B"), Cells(fin, "B")).MergeCells = True
            ini = i
        End If
        fin = i
        an1 = Cells(i, "A").Value
        an2 = Cells(i, "B").Value
    Next
End Sub

'.[Sal u dos. Dante Amor. No olvides valorar la respuesta. 

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas