Copy from sheet1 to sheet3 with all formats

FFaria

New Member
Joined
Oct 20, 2022
Messages
4
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
Hi friends,
Need some help...
When clicking a button below code is executed, which basically, if meeting a certain criteria, copys data from sheet1 to sheet3 and then delets copied data in sheet1.
The problem is that it doesn't copy data with formats, colors, comments, etc., and I would like it to copy exactly everything.

PIC1 = Sheet1
pic1.png

PIC2 = Sheet3
pic2.png


Can you help with the code to make it do that?

VBA Code:
Sub refresh()
'
' Macro3 Macro
'


Application.ScreenUpdating = False
y = Sheets("Folha1").Range("A7").End(xlDown).Row

For i = 7 To y
DoEvents
x = Sheets("Folha3").Range("A4").End(xlDown).Row + 1
If Sheets("Folha1").Range("AD" & i).Value = 0 And Sheets("Folha1").Range("AE" & i).Value <> 0 Then
Sheets("Folha3").Range("A" & x & ":AH" & x).Value = Sheets("Folha1").Range("A" & i & ":AH" & i).Value
Sheets("Folha3").Select
Range("A7:AH7").Select
    Selection.Copy
   Sheets("Folha3").Range("A" & x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
Sheets("Folha1").Select
Range("AD7").Select
    Selection.Copy
   Sheets("Folha3").Select
   Range("AD" & x).Select
    
    ActiveSheet.Paste
    Application.CutCopyMode = False
      Sheets("Folha1").Select
      Range("AF7").Select
    Selection.Copy
    Sheets("Folha3").Select
    Range("AF" & x).Select
    
    ActiveSheet.Paste
    Application.CutCopyMode = False
End If

    Next i
Firstrow = 7
LastRow = y
For Lr = LastRow To Firstrow Step -1
With Sheets("Folha1").Cells(Lr, "AD")
If .Value = "0" And .Offset(0, 1) <> 0 Then .EntireRow.Delete

End With
Next Lr
x = Sheets("Folha3").Range("A4").End(xlDown).Row
ActiveWorkbook.Worksheets("Folha3").sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Folha3").sort.SortFields.Add Key:=Range("A7"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Folha3").sort
        .SetRange Range("A7:AH" & x)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Application.ScreenUpdating = False
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think that help you :

VBA Code:
Sub CopySheet1toSheet3()

    'clear Sheet3
    With Worksheets("Sheet3")
        .Cells(1, 1).CurrentRegion.Clear
    End With

    With Worksheets("Sheet1")
        .Cells(1, 1).CurrentRegion.Copy _
            Destination:=Worksheets("Sheet3").Cells(Rows.Count, 1).End(xlUp)
    End With

End Sub
 
Upvote 0
I think that help you :

VBA Code:
Sub CopySheet1toSheet3()

    'clear Sheet3
    With Worksheets("Sheet3")
        .Cells(1, 1).CurrentRegion.Clear
    End With

    With Worksheets("Sheet1")
        .Cells(1, 1).CurrentRegion.Copy _
            Destination:=Worksheets("Sheet3").Cells(Rows.Count, 1).End(xlUp)
    End With

End Sub
Thank you for trying to help, but it doesn't work along with the current code. Unless it's intended to substitute some row codes in the orginal code?
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,600
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top