Copying listrow throws an error (copy method of range class failed) why?

Lil2606

Board Regular
Joined
Jan 29, 2019
Messages
76
Hi all,

I have the following code:

Code:
[COLOR=#333333]If Not Intersect(Selection, ActiveSheet.ListObjects(1).DataBodyRange) Is Nothing Then[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">
Dim CopyRownr As Long

CopyRownr = ActiveCell.Row - ActiveSheet.ListObjects(1).HeaderRowRange.Row


Dim CopyRow As Range

Set CopyRow = ActiveSheet.ListObjects(1).ListRows(CopyRownr).Range

CopyRow.Copy Destination:=ActiveSheet.ListObjects(2).ListRows.Add       'This is the highlighted line by the debugger
 </code>[COLOR=#333333]End if[/COLOR]
Which is supposed to copy the row (my active cell is in) from the first table to the second, exactly as it is. The second table is the exact copy of the first under a different name and it's databodyrange deleted. I do have formulas in the last 3 columns (sum formulas to sum a range from the same row like: "=SUM([@[a column]:[another column]])") I don't know if they are the trouble makers.. I just don't know why this won't work....

Please help!

Posted on ExcelForum as well. Link:
https://www.excelforum.com/excel-programming-vba-macros/1277380-copying-listrow-throws-an-error-copy-method-of-range-class-failed-why.html#post5127244
 

Lil2606

Board Regular
Joined
Jan 29, 2019
Messages
76
Solution:

Code:
[COLOR=#333333]If Not Intersect(Selection, ActiveSheet.ListObjects(1).DataBodyRange) Is Nothing Then[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim CopyRownr As Long

CopyRownr = ActiveCell.Row - ActiveSheet.ListObjects(1).HeaderRowRange.Row


Dim CopyRow As Range

Set CopyRow = ActiveSheet.ListObjects(1).ListRows(CopyRownr).Range

CopyRow.Copy Destination:=ActiveSheet.ListObjects(2).ListRows.Add.Range       '.RANGE!!!!!!!!!</code><code style="color: rgb(51, 51, 51); font-size: 12px; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; line-height: 12px;"> </code>[COLOR=#333333][COLOR=#333333]End if[/COLOR][/COLOR]
 

Forum statistics

Threads
1,081,530
Messages
5,359,347
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top