Macros para hacer y eliminar copias de una hoja de Excel

Insertamos un módulo en el VBAProject (PERSONAL.XLSB)


Copiamos el siguiente código:

Sub CopiarHoja()
    Dim H As String
    Dim C As Integer
    Dim i As Integer
    H = UCase(Trim(InputBox("Ingrese nombre de la hoja a copiar:")))
    C = InputBox("Ingrese el número de copias:")
    For i = 1 To C
        Sheets(H).Copy After:=Sheets(Sheets.Count)
    Next i
End Sub

Sub EliminarCopias()
    Dim H As String, i As Integer
    H = InputBox("Ingrese nombre de la hoja original:")
    If H <> "" Then
        For i = Sheets.Count To 1 Step -1
            If InStr(1, UCase(Sheets(i).Name), UCase(H & " (")) > 0 And Sheets(i).Name <> H Then
                Application.DisplayAlerts = False
                Sheets(i).Delete
                Application.DisplayAlerts = True
            End If
        Next i
    Else
        MsgBox "No se ingresó el nombre de la hoja original."
    End If
End Sub

Pegamos y Guardamos el código:


Ahora la macro estará disponible para emplearse en cualquier archivo

Comentarios