I am newbie to VBA excel. I am trying to use Set to assign some data from a filtered column (through AutoFilter) to a variable (X in this case). Below shows the code and image of the table.
Sub Test()
Dim X As Variant
Worksheets("Sheet1").Range("B2").AutoFilter _
Field:=2, _
Criteria1:="1"
With Worksheets("Sheet1")
Set X = .Range("D3:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
End With
End Sub
The filtering works as I expected. However, I ended up setting the entire unfiltered data in the range of D3:D23 to X. How can I assign the filtered data from column D to X?