¿Cómo altera una MACRO en cambios de posición en columnas?

En el archivo que te mandé, y en el caso que quisiéramos modificar el orden de las columnas, por ejemplo poner el DNI en la columna G en lugar de la B, ¿cómo modificaría esto a la macro?

1 respuesta

Respuesta
1

En un correo nuevo envíame tu archivo para revisarlo

R ecuerda poner tu nombre de usuario "xitus" en el asunto del correo.

Ya lo tienes, saludos.

Te anexo la macro actualizada

Sub Buscar_Dni()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Set h1 = Sheets("Resultados")
    Set h2 = Sheets("Datos")
    '
    h1.Rows("6:" & Rows.Count).ClearContents
    If h1.Range("C4") = "" Then
        MsgBox "Captura el DNI"
        h1.Range("C4").Select
        Exit Sub
    End If
    '
    Set r = h2.Cells
    Set b = r.Find(h1.Range("C4"), LookAt:=xlWhole)
    If Not b Is Nothing Then
        celda = b.Address
        Do
            'detalle
            año = h2.Cells(2, b.Column - 5)
            col = ""
            For i = 5 To h1.Cells(4, Columns.Count).End(xlToLeft).Column
                If h1.Cells(4, i) = año Then
                    col = i
                    Exit For
                End If
            Next
            '
            If col <> "" Then
                f = 6
                Do While h1.Cells(f, col + 1) <> ""
                    f = f + 1
                Loop
                h1.Cells(f, col + 1) = h2.Cells(b.Row, b.Column - 4)    'exp
                h1.Cells(f, col + 2) = h2.Cells(b.Row, b.Column - 2)    'tip
                h1.Cells(f, col + 3) = h2.Cells(b.Row, b.Column - 1)    'tit
                h1.Cells(f, col + 4) = h2.Cells(b.Row, b.Column + 1)    'cli
                h1.Cells(f, col + 5) = h2.Cells(b.Row, b.Column + 2)    'imp
            End If
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
    End If
    Application.ScreenUpdating = True
    MsgBox "fin"
End Sub

R ecuerda cambiar la valoración a la respuesta. Sal u do

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas