ariel20029
Board Regular
- Joined
- Jun 20, 2013
- Messages
- 97
Hi, I am getting an undefined sub error message on this macro I modified. I am guessing its something very simple I did causing the problem. The macro is to copy and paste from one spreadsheet to another 2 different ranges ( offsetting Journal entries). The original code was to copy from one workbook to another, I just modified it from one spreadsheet to another, but I broke it.. Can you see what I did wrong..? Also I need to copy paste special not just copy.. is there a simple change for that modification?
thanks a million.
Sharon
this is the main code I changed
[TABLE="width: 789"]
<tbody>[TR]
[TD="colspan: 5"]Set wsCopy = Worksheets("JE Setup")[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] Set wsDest = Worksheets("Journal Entry")
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 789"]
<colgroup><col span="7"><col></colgroup><tbody>[TR]
[TD="colspan: 5"]Sub Copy_Paste_Below_Last_Cell()
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"]'Find the last used row in both sheets and copy and paste data below existing data.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim wsCopy As Worksheet[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim wsDest As Worksheet[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim lCopyLastRow As Long[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim lDestLastRow As Long[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"] 'Set variables for copy and destination sheets[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] Set wsCopy = Worksheets("JE Setup")[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] Set wsDest = Worksheets("Journal Entry")[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '1. Find last used row in the copy range based on data in column P[/TD]
[/TR]
[TR]
[TD="colspan: 8"] lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "P").End(xlUp).Row[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '2. Find first blank row in the destination range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 5"] 'Offset property moves down 1 row[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"] '3. Copy & Paste Data[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] wsCopy.Range("P4:Z" & lCopyLastRow).Copy _[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] wsDest.Range("A" & lDestLastRow)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '1. Find last used row in the copy range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 8"] lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "P").End(xlUp).Row[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '2. Find first blank row in the destination range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 5"] 'Offset property moves down 1 row[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"] '3. Copy & Paste Data[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] wsCopy.Range("AB4:AL" & lCopyLastRow).Copy _[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] wsDest.Range("A" & lDestLastRow)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
thanks a million.
Sharon
this is the main code I changed
[TABLE="width: 789"]
<tbody>[TR]
[TD="colspan: 5"]Set wsCopy = Worksheets("JE Setup")[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] Set wsDest = Worksheets("Journal Entry")
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 789"]
<colgroup><col span="7"><col></colgroup><tbody>[TR]
[TD="colspan: 5"]Sub Copy_Paste_Below_Last_Cell()
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"]'Find the last used row in both sheets and copy and paste data below existing data.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim wsCopy As Worksheet[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim wsDest As Worksheet[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim lCopyLastRow As Long[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]Dim lDestLastRow As Long[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"] 'Set variables for copy and destination sheets[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] Set wsCopy = Worksheets("JE Setup")[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] Set wsDest = Worksheets("Journal Entry")[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '1. Find last used row in the copy range based on data in column P[/TD]
[/TR]
[TR]
[TD="colspan: 8"] lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "P").End(xlUp).Row[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '2. Find first blank row in the destination range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 5"] 'Offset property moves down 1 row[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"] '3. Copy & Paste Data[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] wsCopy.Range("P4:Z" & lCopyLastRow).Copy _[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] wsDest.Range("A" & lDestLastRow)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '1. Find last used row in the copy range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 8"] lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "P").End(xlUp).Row[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] '2. Find first blank row in the destination range based on data in column A[/TD]
[/TR]
[TR]
[TD="colspan: 5"] 'Offset property moves down 1 row[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"] lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"] '3. Copy & Paste Data[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 6"] wsCopy.Range("AB4:AL" & lCopyLastRow).Copy _[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"] wsDest.Range("A" & lDestLastRow)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]