I need to write a program that stores names (located in the 2nd column) in an array when the name has an "X" in the 8th column, but I'm having trouble with putting names in the array. When I run it now, I get a blank value for the value in the array. After some debugging, I found out that the i value that tells which spot in the array is selected turns out to be 0, which is not what I wanted.
Here's the code:
Dim rowCount As Integer
Dim duplicateNames(100) As String
Dim duplicateNameCounter As Integer
duplicateNameCounter = 0
'Count the number of rows'
rowCount = WorksheetFunction.CountA(Range("B1:B5000"))
'Find the names with an X next to them and put them in the array'
For i = 1 To 100
If Cells(i, 8).Value = "X" Then
MsgBox ("Found a name to put in the array!")
duplicateNames(i) = Cells(i, 2).Value
duplicateNameCounter = duplicateNameCounter + 1
End If
Next i
'Show the contents of the array'
For i = 1 To duplicateNameCounter
MsgBox ("Here's the slot in the array: " & i & vbNewLine & "Here's the name: " & duplicateNames(i))
Next i
This is my first time using arrays in VBA, so I think that's where my problem is. I have a background in C++ arrays, but these don't seem too different.
Any help would be appreciated. Thanks!
duplicateNames(i) = Cells(i, 2).Valueto beduplicateNames(duplicateNameCounter) = Cells(i, 2).Value