So i am really new to excel and I am trying to copy some values in a cell into an array and later display the array in a column. So what I have is a list of first names in a column(A).Then I have a list of numbers next to the names in column(B). So what I am trying to do is loop through the numbers and if any of the numbers equals 4. copy the name corresponding to the number into my array. and later display that array lets say in column D. This is what I have so far.
Option Explicit
Public Sub loopingTest()
Dim FinalRow As Long '
Dim i As Long 'varable that will loop through the column
Dim maxN As Integer 'variable that will hold the maximum number
Dim j As Long 'variable that will hold the index of the array
Dim ArrayTest As Variant
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row ' will get the last row
For i = 1 To FinalRow 'loop until the last row
If Range("B" & i) = 4 Then 'if any of the values of column B matches 4 then
ArrayTest(j) = Range("A" & i) 'copy the value corresponding to column A to the array
j = j + 1 'increment array index
End If 'end of endif
Next i 'increment column
'output array into column D
For x = 1 to FinalRow
Range("D" & x) = ArrayTest(x)
Next x
End Sub
Would this be a correct way of doing this? Also if I would update column B to any numbers I would love column D to update automatically. Any help would be appreciated