There is such a macro code. Why doesn't he add items to the collection? No logs / errors does not issue. Just does not add it.

Dim cellRanges, cValues As Collection Dim it1, it2, it3, it4, it5, it6, it7, it8 As String it1 = "L3" it2 = "J18" it3 = "J19" it4 = "J20" it5 = "K23" it6 = "J24" it7 = "B86" it8 = "K86" cellRanges.Add (it1) cellRanges.Add (it2) cellRanges.Add (it3) cellRanges.Add (it4) cellRanges.Add (it5) cellRanges.Add (it6) cellRanges.Add (it7) cellRanges.Add (it8) 

    1 answer 1

    Because if you write:

     Dim cellRanges, cValues As Collection 

    Then you declare as a collection only the variable cValues . In VBA (unlike other PLs where you can write, for example, String a, b, c , declaring several variables of the same type), you need to specify its type each time after a variable is declared.

    Correct the beginning of the macro to:

     Dim cellRanges As New Collection, cValues As New Collection 'объявление и создание 
    • Tell me, please, and the format of the announcement As New instead of As concerns only Collections? - Skotinin
    • @Skotinin, As New - this is generally different, and probably you do not need. Simply create a new collection in the next line and assign it to a variable. - Qwertiy
    • Understood. As indicates the type of the declared variable; As New creates an instance of the Collection class. Not enough sleep, I guess. - Skotinin