Adding row to table

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a table to which I wish to add data. Previously, I've been simply copying an entire row to the next blank row (from one sheet of input data to an archive), but I've recently began to poke around with the power of using tables. With that said, I'm struggling to adjust to the new method of working a little. My source data is added to the archive when the macro is ran (QAT button) and by checking Column C. I was using the logic "for each range in C:C if range "Complete" entirerow.copy" and then pasting it to the archive sheet.

The below code is as far as I've got attempting to convert that logic, but obviously it doesn't work.

VBA Code:
Sub MoveCompletedTasks2()



Dim sTasks As Worksheet

Dim cTasks As Worksheet

Dim archTable As ListObject



Dim newRow As ListRow



Set sTasks = ThisWorkbook.Sheets("Test")

Set Archive = ThisWorkbook.Sheets("Archive")

Set archTable = Archive.ListObjects("Archive")



Set newRow = archTable.ListRows.Add()



For Each cell In sTasks.Range("C:C")

If cell.Value = "Complete" Then newRow = cell.EntireRow.Value

Next cell



End Sub

Thanks for any help
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Here is a starting point. This will only work if both tables have the same number of columns and that they are in the same order.
It also assumes that that in Test Row 1 is the headings and the data starts in Row 2

VBA Code:
Sub MoveCompletedTasks2()

Dim sTasks As Worksheet
Dim wsTasks As Worksheet
Dim wsArchive As Worksheet
Dim tblArchive As ListObject
Dim newRow As ListRow

Set wsTasks = ThisWorkbook.Sheets("Test")
Set wsArchive = ThisWorkbook.Sheets("Archive")
Set tblArchive = wsArchive.ListObjects("Archive")


For Each rCell In wsTasks.Range("C2:C" & wsTasks.Cells(Rows.Count, "C").End(xlUp).Row)
    If rCell.Value = "Complete" Then
        Set newRow = tblArchive.ListRows.Add()
        newRow.Range.Value = Intersect(rCell.EntireRow, rCell.CurrentRegion).Value
    End If

Next rCell

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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