PDA

View Full Version : [SOLVED:] Vertical progress bar with label and changing height - only "grows" downward



kcsteele
04-06-2023, 09:50 AM
I created a horizontal progress bar by increasing the width value of a label, and the label grew to the right, which was fine.

I then tried to create a vertical progress bar, but it grows down instead of up from the bottom.



Sub RunStatusBar4(cellNum As Integer, totalCells As Integer)
With StatusBar
.Bar4.Height = 426 * (cellNum / totalCells)
.FrameProgressBarFull.Caption = Int((cellNum / totalCells) * 100) & "%"
.LabelTotalValuesChanged = cellNum
End With
End Sub

p45cal
04-06-2023, 10:52 AM
I think I can do this, but could you attach a workbook with the progress bar as it is, then I can be sure any solution I offer is going to work for you?

kcsteele
04-06-2023, 04:05 PM
thanks, here it is

kcsteele
04-06-2023, 04:55 PM
I didn't fix it but I found a workaround, just put a label on top and made it grow backwards. barsizeGlobal is the height of the label which is taken from the height property at the start, instead of hardcoding it like I did above.


Sub RunStatusBar4(cellNum As Integer, totalCells As Integer) With UserForm1
'.Bar4.Height = barsizeGlobal * (cellNum / totalCells)
.Bar4White.Height = barsizeGlobal - (barsizeGlobal * (cellNum / totalCells))
.FrameProgressBarFull.Caption = Int((cellNum / totalCells) * 100) & "%"
End With
End Sub

Attached the fix for anyone else who might run into it, unless you know a different way. I was thinking maybe there's a property that sets the "anchor" or the text behavior on the label, or a way to rotate it, but didn't find anything.

p45cal
04-06-2023, 05:09 PM
try on your first attached file:
Sub RunStatusBar4(cellNum As Integer, totalCells As Integer)
With UserForm1
ht = 426 * (cellNum / totalCells)
.Bar4.Top = 426 - ht
.Bar4.Height = ht
.FrameProgressBarFull.Caption = Int((cellNum / totalCells) * 100) & "%"
End With
End Sub

arnelgp
04-06-2023, 06:31 PM
you can also set the Bar4 (green) to "Bring Forward" and use this code (same as #5):

Sub RunStatusBar4(cellNum As Integer, totalCells As Integer) Dim h As Integer
With UserForm1
'.Bar4.Height = barsizeGlobal * (cellNum / totalCells)
'.Bar4White.Height = barsizeGlobal - (barsizeGlobal * (cellNum / totalCells))
With .Bar4
h = barsizeGlobal * (cellNum / totalCells)
.Top = barsizeGlobal - h
.Height = h
End With
.FrameProgressBarFull.Caption = Int((cellNum / totalCells) * 100) & "%"
End With
End Sub


Private Sub UserForm_Initialize()
With Me.Bar4
.Height = 0
.Top = barsizeGlobal
End With
End Sub




Private Sub CommandButton1_Click()
ThisWorkbook.runit
End Sub

kcsteele
04-07-2023, 06:48 AM
Thanks so much to both of you, this is more what I was looking for! :yes