Run-time error '-2147024809 (80070057') The index into the specified collection is out of bounds

bmunkel

New Member
Joined
Oct 27, 2015
Messages
7
Please bear with me...learning as I go
I have a macro that I have run successfully in Excel for the past two years but continue to get the following message on my latest project: "Run-time error '-2147024809 (80070057') The index into the specified collection is out of bounds". I am referencing more shapes than I have done in previous iterations (204 shapes in file) but not sure if that has anything to do with the issue. The macro follows:

Sub MapMacro()

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">For i =5To207
Range
("actReg").Value = Range("A"& i).Value

If ActiveSheet.Name ="Variables"Then
Worksheets
("Map").Activate
EndIf

ActiveSheet
.Shapes(Range("actReg").Value).Select
Selection
.ShapeRange.Fill.ForeColor.RGB = Range(Range("actRegCode").Value).Interior.Color

If ActiveSheet.Name ="Map"Then
Worksheets
("Variables").Activate
EndIf

Next i

Range
("A1").Select
</code>End Sub

Any assistance is greatly appreciated!!!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
I get the error when the actReg range has 211 in it because there are only 205 shapes on the sheet, so you can't select shape 211.

Also, you could eliminate all that flickering like this:

Code:
Sub MapMacro()
    Dim mapSheet As Worksheet
    Dim varSheet As Worksheet
    
    Set mapSheet = Worksheets("Map")
    Set varSheet = Worksheets("Variables")
    
    For i = 5 To 207
        varSheet.Range("actReg").Value = varSheet.Range("A" & i).Value
        mapSheet.Shapes(Range("actReg").Value).Fill.ForeColor.RGB = varSheet.Range("actRegCode").Interior.Color
    
    Next i

End Sub
 
Last edited:

bmunkel

New Member
Joined
Oct 27, 2015
Messages
7
Many thanks (sometimes the solution is simple)!!! Worked for the first few and assume it will work for the rest...will just go through and rename shapes to include verbiage as well as numbers and should run perfectly....much appreciated!

I get the error when the actReg range has 211 in it because there are only 205 shapes on the sheet, so you can't select shape 211.

Also, you could eliminate all that flickering like this:

Code:
Sub MapMacro()
    Dim mapSheet As Worksheet
    Dim varSheet As Worksheet
    
    Set mapSheet = Worksheets("Map")
    Set varSheet = Worksheets("Variables")
    
    For i = 5 To 207
        varSheet.Range("actReg").Value = varSheet.Range("A" & i).Value
        mapSheet.Shapes(Range("actReg").Value).Fill.ForeColor.RGB = varSheet.Range("actRegCode").Interior.Color
    
    Next i

End Sub
 

Forum statistics

Threads
1,082,269
Messages
5,364,148
Members
400,783
Latest member
sambills

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top