Have been needing this for my automation, and kinda stuck with this part of the code. A have a file with a few sheets, I need to extract values from each not empty cell into a column on another sheet.
Would be awesome if while doing that duplicates can be removed as well.
At the moment I use the following code, but it infinitely loops, and I don't see the way how to break the loop since all the events are being used in the body of the code.
Range of where the cells are being looked for on both sheets are different, that is why I used .End(xlUp). to define the last row with values in cells.
Also I cannot use empty cells as a trigger for stopping the loop, because there are plenty of empty cell along the way and between cells with values.
Sub updt()
Dim ws As Worksheet, currWs As Worksheet, Lng As Integer, rng As Range
Set ws = wb.Worksheets("Sheet1") 'the source sheet
Set currWs = Sheets("Sheet2") 'the destination sheet
Lng = ws.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ws.Range("A2:A" & Lng)
For Each c Lng rng
If WorksheetFunction.CountIf(currWs.Range("A:A"), c.Value) = 0 Then
currWs.Range("A" & currWs.Cells(Rows.Count, 1).End(xlUp).Row)(2) = c.Value
End If
Next
End Sub
Would appreciate your help, could be fixed above text or maybe there is another solution I can apply to solve this problem.