Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

For something like this I think you can do everything in a single loop instead of multiple loops and trying to keep track of everything. Try this.

Dim assemblyDoc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument

Dim cubeOccurrencePrefix = "Cube:"

Dim numberOfOccurrences As Integer = 0

For Each occurrence As Inventor.ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences
	If occurrence.Name.Contains(cubeOccurrencePrefix) Then 
		numberOfOccurrences += 1
		occurrence.Name = cubeOccurrencePrefix & numberOfOccurrences
		Component.IsActive(occurrence.Name) = False
	End If
Next