I have two excel tables on two different sheets: "Open" and "Hold or Closed".
On the "Open" sheet, I am trying to cut a row inside the table and paste it into the "Hold or Closed" Table if the "CLOSED_DATE" column record is populated. If not populated, nothing happens.
My code is successful on the first iteration, but if I run it again, I get the spinning wheel of death, which leads to my workbook closing without an error message on the second iteration.
Here is my code, maybe there's an infinite loop somewhere.
Sub CutPasteRows()
Dim sourceTable As ListObject
Dim newTable As ListObject
Dim sourceRange As Range
Dim targetRange As Range
Dim Count As Integer
Dim i As Long
Dim ii As Long
Set sourceTable = Worksheets("Open").ListObjects("Current_Ops_TBL8")
Set newTable = Worksheets("Hold or Closed").ListObjects("Hold_Closed_TBL3")
Set targetTable = Worksheets("Hold or Closed")
Count = 4
ii = sourceTable.Range.Rows.Count
Debug.Print (sourceTable.ListColumns("IAA CLOSED DATE").DataBodyRange.Rows.Count())
For Each iListRow In sourceTable.ListColumns("IAA CLOSED DATE").DataBodyRange.Rows
Debug.Print (iListRow)
If iListRow.Value <> "" Then
Debug.Print (iListRow.Value)
Worksheets("Open").Rows(Count).Copy
targetTable.Rows("2").Insert
Worksheets("Open").Rows(Count).Clear
End If
Count = Count + 1
Next iListRow
End Sub
I expect every time I insert a date in the "CLOSED_DATE" column and select run macro, the "Open" sheet row gets pasted in the "Hold or Closed" sheet. The "Open" sheet row will become blank.
If someone can teach me some VBA here that would be splendid.
Thank you in advance.