I have an excel table with values. I am trying to use VBA such that:
- Rows where Col <> 0 gets copied to one worksheet
- Rows where Col = 0 gets copied to another worksheet
The code, I have is from below, taken from here. But with the below, I only manage to copy 1, and not rows with criteria specified in 2.
Sub ExportData()
Dim rngJ As Range
Dim MySel As Range
Set rngJ = Range("O1", Range("O" & Rows.Count).End(xlUp))
Set wsNew = ThisWorkbook.Worksheets.Add
For Each cell In rngJ
If cell.Value <> 0 Then
If MySel Is Nothing Then
Set MySel = cell.EntireRow
Else
Set MySel = Union(MySel, cell.EntireRow)
End If
End If
Next cell
If Not MySel Is Nothing Then MySel.Copy Destination:=wsNew.Range("A1")
End Sub