Tarkemelion
New Member
- Joined
- Jun 28, 2022
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Hi All,
I have what I thought would be a simple copy/paste macro which appears to ignore my attempts to put a constraint on it. I'm sure there is something I am missing but I can't seem to spot it. Any help would be appreciated!
Ideally the code looks at Table 2 and checks the column in the 16th position. If that number is not a 0 (+/- integers allowed) then I want to copy that row and paste it into the empty Table 6. If the value is a zero then I want to skip that row and move on to the next.
Eventually I will add a line to clear Table 6 each time the Macro is run but perhaps that is for another day.
Additional style points will be warded for...well...style!
I have what I thought would be a simple copy/paste macro which appears to ignore my attempts to put a constraint on it. I'm sure there is something I am missing but I can't seem to spot it. Any help would be appreciated!
Ideally the code looks at Table 2 and checks the column in the 16th position. If that number is not a 0 (+/- integers allowed) then I want to copy that row and paste it into the empty Table 6. If the value is a zero then I want to skip that row and move on to the next.
Eventually I will add a line to clear Table 6 each time the Macro is run but perhaps that is for another day.
VBA Code:
Sub Copy_Paste()
Dim i, iLastRow As Integer
Dim srcRow As Range
Set tbl2 = Worksheets("Cost").ListObjects("Table2")
Set tbl6 = Worksheets("Not Costs").ListObjects("Table6")
iLastRow = tbl2.ListRows.Count
For i = 1 To iLastRow
If tbl2.Range.Cells(i, 16).Value <> 0 Then
Set srcRow = tbl2.ListRows(i).Range
tbl6.ListRows.Add
srcRow.Copy
tbl6.ListRows(i).Range.PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
Next
End Sub
Additional style points will be warded for...well...style!