Robert Germain
New Member
- Joined
- Mar 18, 2003
- Messages
- 11
Hi all,
I have this code (thank you Fluff) where it copies and pastes data in the last empty line in a worksheet. I would need to improve on that by ensuring that this code takes into consideration that the last non empty line is my Totals line and therefore it has to insert the copied data above this line and to respect the formatting of the rows and columns in the process. The inserted data may vary in the amount of rows to be pasted.
Thank you for your assistance in advance!
Code
Sub Copy_data_2()
Dim Ws As Worksheet
Dim Sht As String
Dim LASTROW As Long
Sht = InputBox("Please enter sheet name")
On Error Resume Next
Set Ws = Workbooks("2018_CONTABILIDAD TOTAL.xlsm").Sheets(Sht)
On Error GoTo 0
If Ws Is Nothing Then
MsgBox "Sheet " & Sht & " does not exist"
Exit Sub
End If
With ActiveSheet
.Range("B5:E" & .Cells(Rows.Count, 2).End(xlUp).Row).Copy
End With
Ws.Range("G" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End Sub
[/code]
I have this code (thank you Fluff) where it copies and pastes data in the last empty line in a worksheet. I would need to improve on that by ensuring that this code takes into consideration that the last non empty line is my Totals line and therefore it has to insert the copied data above this line and to respect the formatting of the rows and columns in the process. The inserted data may vary in the amount of rows to be pasted.
Thank you for your assistance in advance!
Code
Sub Copy_data_2()
Dim Ws As Worksheet
Dim Sht As String
Dim LASTROW As Long
Sht = InputBox("Please enter sheet name")
On Error Resume Next
Set Ws = Workbooks("2018_CONTABILIDAD TOTAL.xlsm").Sheets(Sht)
On Error GoTo 0
If Ws Is Nothing Then
MsgBox "Sheet " & Sht & " does not exist"
Exit Sub
End If
With ActiveSheet
.Range("B5:E" & .Cells(Rows.Count, 2).End(xlUp).Row).Copy
End With
Ws.Range("G" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End Sub
[/code]