Not enough memory crash when loading VBA userform

前端 未结 2 536
無奈伤痛
無奈伤痛 2021-01-01 07:47

Background:

I have a VBA userform with ~1050 checkboxes, and ~100 labels, all populated from the active Sheet. The labels are taken directly from t

2条回答
  •  旧巷少年郎
    2021-01-01 08:01

    I can't speak to why your Excel is crashing, but you could probably cut down some code by loading some values into an Array, then instead of 6 For v = 0 to 28 loops you could have two nested loops, the inner one iterating through your array:

    Dim start As Long, z As Long, arr As Variant
    
    start = 1
    arr = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9")
    
    For v = 0 To 28
        For z = 0 To UBound(arr)
            If Len(WorksheetFunction.Substitute(.Cells(r, c + 3 + v), arr(z), "")) < Len(.Cells(r, c + 3 + v)) Then Controls("CheckBox" & start + v).Value = True
            start = start + 30
        Next z
        start = 1
    Next 
    

提交回复
热议问题