VBA Building An Array (I think) of different items

Lotus Cars

Board Regular
Joined
Feb 4, 2011
Messages
55
Hi all,

I have two columns, one with numbers that could be individual, could be duplicate on another row. The second either has entries in, or is blank.

ie

8945
8946 identified
9405 identified
8945
1575

What I want is to go down the second column, identify the blanks, and put them into an individual array. However, if the number is duplicate, then I only want it once.

I'd got this far...


Dim blanks As String
Dim empties As String


Range("O2").Select
blanks = "Missing Project Numbers - "
Do
If ActiveCell = "" Then
n = 1
Do
If empties(n) = "" Then empties(n) = ActiveCell.Offset(0, -11)
n = n + 1
Loop Until empties(n) = ActiveCell.Offset(0, -11)


End If

ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(0, -10) = ""
Range("A1").Select

but it does not like putting a number against empties to create the unique string / array.

Any ideas?

Cheers,

Lotus Cars
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Sorry, got some of my coding wrong, but still have the same problem. Any help would be appreciated.

Sub anothercheckbalnks()
Dim blanks As String
Dim empties As String
Dim n As Integer

Range("O2").Select
blanks = "Missing Project Numbers - "
Do
If ActiveCell = "" Then
n = 1
Do
If empties(n) = "" Then empties(n) = ActiveCell.Offset(0, -11)
n = n + 1
Loop Until empties(n) = ActiveCell.Offset(0, -11)
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(0, -10) = ""

n = 1
Do
blanks = blanks & empties(n) & ", "
n = n + 1
Loop Until empties(n) = ""
If blanks <> "Missing Project Numbers - " Then MsgBox blanks

End Sub



Cheers,

Lotus Cars
 
Upvote 0
Name your data (2 columns by many rows) myData

Code:
Option Explicit
Option Base 1

Sub myExample()
Dim myArray As Variant
Dim Numbers As Variant
Dim i As Double

On Error GoTo err


    ' First, sort the data in the spreadsheet by numbers (faster than VBA)
    [myData].Sort Key1:=Range([myData].End(xlToLeft).Offset(0, 1).Address), Order1:=xlAscending
    
    myArray = [myData] ' this is my named range (data)
    ReDim Numbers(1)
    
    ' Get the list of IDs / numbers that are not flagged
    For i = LBound(myArray) To UBound(myArray)
        If myArray(i, 2) = "" Then
            If UBound(Numbers) = 1 And Numbers(1) = "" Then
                Numbers(1) = myArray(i, 1)
            Else
                ReDim Preserve Numbers(UBound(Numbers) + 1)
                Numbers(UBound(Numbers)) = myArray(i, 1)
            End If
        End If
    Next i
    
    Erase myArray
    ReDim myArray(1)
    
    ' Time to remove duplicates
    For i = LBound(Numbers) To UBound(Numbers)
        If i = UBound(Numbers) Then
            If UBound(myArray) = 1 And myArray(1) = "" Then
                myArray(1) = Numbers(i)
            Else
                ReDim Preserve myArray(UBound(myArray) + 1)
                myArray(UBound(myArray)) = Numbers(i)
            End If
        Else
            If Numbers(i) <> Numbers(i + 1) Then
                If UBound(myArray) = 1 And myArray(1) = "" Then
                    myArray(1) = Numbers(i)
                Else
                    ReDim Preserve myArray(UBound(myArray) + 1)
                    myArray(UBound(myArray)) = Numbers(i)
                End If
            End If
        End If
    Next i
    Erase Numbers
    
    MsgBox "Complete"
    
    ' myArray has all the values you need in it

Exit Sub

err:
    MsgBox err.Description, vbExclamation, "Error"

End Sub

:)

P.S. I'll have an Exige please. :)
 
Last edited:
Upvote 0
Cheers for your help - it does seem a bit complicated to follow, but it did seem to work.

I'll do my best for the car!
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top