Public Type myCellsCopy
copySheetName As String
pasteSheetName As String
copyTopL_Row As Long
copyTopL_Col As Long
copyBottomR_Row As Long
copyBottomR_Col As Long
pasteRow As Long
pasteCol As Long
End Type
Sub main()
On Error GoTo errHdl
Dim errString As String
Dim i As myCellsCopy
With i
.copySheetName = "P1"
.pasteSheetName = "Sheet1"
.copyTopL_Row = 1
.copyTopL_Col = 1
.copyBottomR_Row = 3
.copyBottomR_Col = 4
.pasteRow = 1
.pasteCol = 1
End With
If (copyCell(errString, i) <> True) Then GoTo errHdl
Exit Sub
errHdl:
MsgBox Err.Description
End Sub
Function copyCell(ByRef errCode As String, ByRef info As myCellsCopy) As Boolean
On Error GoTo errHdl
Dim vArray As Variant
Dim rowDiff As Long
Dim colDiff As Long
With info
Sheets(.copySheetName).Select
vArray = Range(Cells(.copyTopL_Row, .copyTopL_Col), Cells(.copyBottomR_Row, .copyBottomR_Col))
Sheets(.pasteSheetName).Select
rowDiff = .copyBottomR_Row - .copyTopL_Row
colDiff = .copyBottomR_Col - .copyTopL_Col
Range(Cells(.pasteRow, .pasteCol), Cells(.pasteRow + rowDiff, .pasteCol + colDiff)) = vArray
End With
copyCell = True
Exit Function
errHdl:
errCode = Err.Description
copyCell = False
End Function