Firstly, many thanks to VoG for supplying the code in use.
The following code will copy columns (A,C,D,E,F) from Book1 to columns (C,A,F,E,D) in Book2. It all works with no errors. My problem now is that I need to have all formatting from selected cells in Book1 removed prior to it being copied to Book2. I know I need to use the PasteSpecial Method, but not sure where in the code to put it.
Regards
Paul S
The following code will copy columns (A,C,D,E,F) from Book1 to columns (C,A,F,E,D) in Book2. It all works with no errors. My problem now is that I need to have all formatting from selected cells in Book1 removed prior to it being copied to Book2. I know I need to use the PasteSpecial Method, but not sure where in the code to put it.
Code:
Sub Copy()
' This will copy selected rows to new spreadsheet
' cannot copy non-contiguous cells. Use filters instead
' Change i number from where copying is to commence from, so if copying from row 5 change to i = 5
On Error GoTo ErrorHandler
Dim LR As Long, LR2 As Long, i As Long
If Selection.Rows.Count > 1 Then
i = Selection.Row
LR = Selection.Row + Selection.Rows.Count - 1
Else
i = 5
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
End If
'Destination row number start point (Row 8) - first data entry row
LR2 = WorksheetFunction.Max(8, Workbooks("Book2.xls").Sheets("Checking").Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1)
Range("A" & i & ":A" & LR).SpecialCells(xlCellTypeVisible).Copy Destination:=Workbooks("Book2.xls").Sheets("Checking").Range("C" & LR2)
Range("C" & i & ":C" & LR).SpecialCells(xlCellTypeVisible).Copy Destination:=Workbooks("Book2.xls").Sheets("Checking").Range("A" & LR2)
Range("D" & i & ":D" & LR).SpecialCells(xlCellTypeVisible).Copy Destination:=Workbooks("Book2.xls").Sheets("Checking").Range("F" & LR2)
Range("E" & i & ":E" & LR).SpecialCells(xlCellTypeVisible).Copy Destination:=Workbooks("Book2.xls").Sheets("Checking").Range("E" & LR2)
Range("F" & i & ":F" & LR).SpecialCells(xlCellTypeVisible).Copy Destination:=Workbooks("Book2.xls").Sheets("Checking").Range("D" & LR2)
Application.CutCopyMode = False
ErrorHandler:
If Err.Number = 5 Or Err.Number = 9 Then
MsgBox "The file could not be found. Please open relevant file named 'Book2.xls' and try again"
MsgBox "Error " & Err & " - " & Err.Description
End If
End Sub
Regards
Paul S