Having some issue with a simple macro. I want to replace retrieve the unique values of column B in worksheet FLMs and paste it to another sheet. It works fine normally but only when I have the FLMs worksheet open and then run the macro. However, the macro button is placed in a different sheet and when I run it from there it returns an error.
This is the code that is used:
Sub GeheleMacro()
Dim lastrow As Long
Dim ws As String
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Sheets("FLMs").Range("B4:B" & lastrow).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Sheets("NIET VERWIJDEREN").Range("A1"), _
UNIQUE:=True
End sub
I already tried using 'Worksheet("FLMs").Activate' after defining lastrow but that didn't work.