LRow of table

Takes2ToTango

Board Regular
Joined
May 23, 2023
Messages
69
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am running into an issue with populating the lrow of a table with copied data. I have pasted the code below. I am trying to get it to copy the data and then with the sheet 'DateQuery' I want it to paste into the lrow of the table. However, I am either getting data overridden or missing the table completely. I have also tried adding '+ 1' onto the end of the .Row.

VBA Code:
  With ws2
        lRow2 = Cells(Rows.Count, 1).End(xlUp).Row
    'Loop from bottom to top deleting according to value in 1st column
        For iCntr2 = lRow2 To 2 Step -1
        
           If Cells(iCntr2, 6) = "QUERY" Then
            Rows(iCntr2).Copy
                With Sheets("DateQuery")
                 lRow3 = Sheets("DateQuery").Range("A" & Rows.Count).End(xlUp).Row  'Tried + 1 on the end of here but causes it to miss the table
                .Range("A" & lRow3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
                End With
            Rows(iCntr2).Delete
            End If
        Next
      End With
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
It is very nasty to nest two Withs together, moreover, with the same type...

Also you have to add a leading . if you want to refer to ws2. I don't know your data astructure but you need something like this:
VBA Code:
    With ws2
    lRow2 = .Cells(Rows.Count, 1).End(xlUp).Row
    For iCntr2 = lRow2 To 2 Step -1
      If .Cells(iCntr2, 6) = "QUERY" Then
        .Rows(iCntr2).Copy
        Sheets("DateQuery").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        .Rows(iCntr2).Delete
      End If
    Next
    End With
 
Upvote 0
Solution
Thanks for your reply. I've used your code as you have said. It is still missing the first line of the table (completely missing the table as a whole and not becoming part of it). Do I need the offset part in there?
 
Upvote 0
1705997096382.png

This is my table here. It starts in range "A1" and I have placed a dummy line in there as tests for the lrow error. Could this be throwing it off perhaps?
 
Upvote 0
Ah my apologies I read it wrong! Yes the table in ws2 is identical to the one above (without the dummy line) starts in range "A1"
 
Upvote 0
The code works! I think it could be the table isn't auto-expanding to capture the new data.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,660
Latest member
Zatman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top