Reputation: 15
I have a beginner question in VBA. Im trying to make a loop to fill an array by phone numbers located at 12 different sheets. When I do the bellow code its only stores the values of first sheet.
For J = 1 To 12
For i = i To UBound(ArrayPhone)
ArrayPhone(i) = Range("P" & i + 2).Value
Next
Worksheets(ActiveSheet.Index + 1).Select
Next
As how I can prevent from storing empty values in the array.
I’d be greatful for any clues as to what I’m doing wrong.
Upvotes: 0
Views: 210
Reputation: 3200
You are always writing into the array starting from position i = 1
for each sheet. This means that your outer loop iterating over sheets is useless.
You would need to size the array appropriately to hold all numbers from all sheets, and then add a counter which counts how many items you've already put into the array.
Upvotes: 1