
Originally Posted by
AlphaFrog
Dim tbl As ListObject
Dim rngFound As Range
Set tbl = Workbooks("MasterWB.xlsm").Worksheets("Sheet1").ListObjects(1)
' This code will copy the data from the slave worksheet and paste to master
For i = 1 To LastRowSlave
With Workbooks("Slave1.xlsm").Worksheets(strName) 'strName is just the ActiveSheet.Name
If .Cells(i, 1).Value = "x" Then 'if there is an x in column A, it's marking it as data that needs to be moved to the master
'Look for a match in column B
Set rngFound = tbl.ListColumns(2).Range.Find(.Range("B" & i), , xlValues, xlWhole, 1, 1, 0)
If Not rngFound Is Nothing Then
'Replace existing row
.Rows(i).Copy
rngFound.EntireRow.PasteSpecial xlPasteValues
Else
'Add to bottom of the table
tbl.ListRows.Add
.Rows(i).Copy
tbl.ListRows(tbl.ListRows.Count).Range.EntireRow.PasteSpecial xlPasteValues
End If
.Cells(i, 1).Value = "Added on " & Date 'This replaces the 'x' with a date the info was added so as to prevent manual marking of these fields
End If
End With
Next i
Application.CutCopyMode = False
Thank you very much for the above!!! I have one more issue to consider, now. Correct me if I'm wrong, but I believe because I'm doing the following, it's copying the entire row, and when it pastes, because it's pasting to a table, every column past the end of my table (just say Column Z) is being re-appropriated as a column that belongs for the table (thus, columns AA:XFD). Is there a way to change the "EntireRow" to a range? I've tried, but can't figure out the algorithm so that it's just Columns A:Z.
...
'Look for a match in column B
Set rngFound = tbl.ListColumns(2).Range.Find(.Range("B" & i), , xlValues, xlWhole, 1, 1, 0)
If Not rngFound Is Nothing Then
'Replace existing row
.Rows(i).Copy
rngFound.EntireRow.PasteSpecial xlPasteValues
Else
'Add to bottom of the table
tbl.ListRows.Add
.Rows(i).Copy
tbl.ListRows(tbl.ListRows.Count).Range.EntireRow.PasteSpecial xlPasteValues
End If
...
Can I change the:
rngFound.EntireRow.PasteSpecial xlPasteValues
to something like:
rngFound.Range((1,1),26,1)).PasteSpecial xlPasteValues[/B]
Or something to that effect, so that when it pastes the entire row to my master table, it doesn't create a bunch of blank columns?
Thank you!
Bookmarks