
Estoy realmente estupefacto por este problema, tengo un bucle anidado para el siguiente que proporciona más de mil bucles. Lo sé al ver este código:
'find row ranges for department 1-10
For i = 1 To 10 Step 1
Dim tempRange As Range
Set tempRange = GetRowRange(importsheet, DepColumn, i)
'and iterate through the columns to insert them
' find row ranges for section
If Not (importsheet.UsedRange.Find("afdeling_" & i) Is Nothing) Then
Dim SecColumn
Dim secRange As Range
SecColumn = importsheet.UsedRange.Find("afdeling_" & i).column
Set bCell = tempRange.Columns(SecColumn)
tempRange.Sort Key1:=bCell, Order1:=xlAscending, Header:=xlYes
For ix = 1 To 10 Step 1
'check for a valid section column
Set secRange = GetRowRange(tempRange, SecColumn, ix)
totalposts = totalposts + IterateColumns(secRange, spgsheet, importsheet, debugsheet, year, month, week, Hospital, i, ix, varType, False)
Progress
Next ix
Else
totalposts = totalposts + IterateColumns(tempRange, spgsheet, importsheet, debugsheet, year, month, week, Hospital, i, 0, varType, False)
End If
Progress
Next i
Mi función de progreso se ve así:
Function Progress()
iProgress = iProgress + 1
Application.StatusBar = Format(iProgress, "0%") & " Completed"
End Function
pero la barra de progreso suele mostrar hasta 3300%.
¿Cómo es eso posible?
Respuesta1
No estás mostrando todo el código. Por ejemplo, supongo que esto iProgress
está definido globalmente, pero no podemos verlo aquí.
Además, ¿por qué haces DIM
declaraciones dentro de un bucle? Solo debes hacerlo una vez y también debes configurar las variables de objeto nothing
una vez que hayas terminado con ellas. De lo contrario, es probable que se produzcan algunos problemas de memoria desagradables en el camino.
Para responder a la pregunta específica. Lo has configurado iProgress
para que sea un contador, no un %.
Para obtener el porcentaje, necesita saber cuántos elementos iterará antes de iniciar la barra de progreso. Luego necesitará el contador de artículos actual y el total. CurrentCount/TotalItemCount
te da el progreso.