¿Cómo mantener formato en macro que copia hoja en excel?

Tengo la siguiente macro que me copia unas celdas en otra hoja de excel, pero quiero que mantenga el formato (ancho de las columnas, sin líneas de cuadrícula, etc. Pero no sé cuál es la instrucción.

Sub Copia()

Dim hoja As Worksheet, existe As Boolean, nueva As String
nueva = Sheets("Plan de Desarrollo").Range("D8")
If nueva = Empty Then Exit Sub
For Each hoja In Worksheets
If hoja.Name = nueva Then existe = True: _
MsgBox "Ya existe el expediente", vbCritical
Next hoja
If existe = False Then
Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = nueva
.Tab.Color = 65535
End With
Sheets("Plan de desarrollo").Range("A1:J115").Copy
Sheets(nueva).Range("A1").PasteSpecial _
Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1:J1").Select
MsgBox "Se Creo Correctamente", vbInformation
Sheets("Plan de Desarrollo").Select
End If

End Sub

Sub Copia()

Dim hoja As Worksheet, existe As Boolean, nueva As String
nueva = Sheets("Plan de Desarrollo").Range("D8")
If nueva = Empty Then Exit Sub
For Each hoja In Worksheets
If hoja.Name = nueva Then existe = True: _
MsgBox "Ya existe el expediente", vbCritical
Next hoja
If existe = False Then
Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = nueva
.Tab.Color = 65535
End With
Sheets("Plan de desarrollo").Range("A1:J115").Copy
Sheets(nueva).Range("A1").PasteSpecial _
Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1:J1").Select
MsgBox "Se Creo Correctamente", vbInformation
Sheets("Plan de Desarrollo").Select
End If

End Sub

1 Respuesta

Respuesta
1

H o l a, bienvenida al foro!

Prueba lo siguiente:

Sub Copia()
  Dim hoja As Worksheet, nueva As String
  Application.ScreenUpdating = False
  '
  Set hoja = Sheets("Plan de Desarrollo")
  nueva = hoja.Range("D8")
  If nueva = Empty Then Exit Sub
  If Evaluate("ISREF('" & nueva & "'!A1)") = True Then
    MsgBox "Ya existe el expediente", vbCritical
    Exit Sub
  End If
  '
  Sheets.Add After:=Sheets(Sheets.Count)
  With ActiveSheet
    .Name = nueva
    .Tab.Color = 65535
    hoja.Range("A1:J115").Copy
    .Range("A1").PasteSpecial Paste:=xlPasteAllUsingSourceTheme
    .Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
  End With
  Application.CutCopyMode = False
  MsgBox "Se Creo Correctamente", vbInformation
  hoja.Select
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas