Results 1 to 4 of 4

Thread: VBA & ProgressBar

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Question VBA & ProgressBar

    My project is linked to a spreadsheet where a lot of calulations are done and a final result is then displayed in 1 of my forms. As the calculations can take some time (30 secs to 1 min) I want to add a progressbar so the user doesn't go mad waiting for the result to be displayed.

    This is the code that does the calculations........so basically I need the min to start at 0 and progress until the "Do While" has finished. I have checked out some examples on progressbars but they all seem to be for DB's or timers. I haven't been able to find an exaple for VBA. Can anyone help me out??
    Code:
    Do While MaxDD < Val(txtMaxDrawDown.Text)
        Range("BC30").Select
        ActiveCell.FormulaR1C1 = Risk
        Worksheets("LBOP-New Capital p.a").Calculate
        Range("BC25").Select
        MaxDD = Range("BC25")
            Risk = Risk - 0.00002
    Loop

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    There are a few ways you can do this. With a popup form you can have a coloured box that grows during the calculation process... with your code I would do something like this..
    VB Code:
    1. Do While MaxDD < Val(txtMaxDrawDown.Text)
    2.     Range("BC30").Select
    3.     ActiveCell.FormulaR1C1 = Risk
    4.     Worksheets("LBOP-New Capital p.a").Calculate
    5.     Range("BC25").Select
    6.     MaxDD = Range("BC25")
    7.         Risk = Risk - 0.00002
    8.     Progress = Val(txtMaxDrawDown.Text) - (MaxDD/Val(txtMaxDrawDown.Text))
    9.     boxProgress.Width = boxOriginal.Width - (boxOriginal.Width * Progress)
    10.     doevents
    11. Loop

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    I declared Progress as ProgressBar but not sure if that's correct. Also changed your "box" code to the name of my ProgressBar. Again not sure if that is correct. After the changes I ran my app but got an error at the "Progress" line. Anyone able to offer some more assistance? Thanks.

    Code:
    Dim Progress As ProgressBar
    
    Do While MaxDD < Val(txtMaxDrawDown.Text)
        Range("BC30").Select
        ActiveCell.FormulaR1C1 = Risk
        Worksheets("LBOP-New Capital p.a").Calculate
        Range("BC25").Select
        MaxDD = Range("BC25")
            Risk = Risk - 0.00002
        Progress = Val(txtMaxDrawDown.Text) - (MaxDD / Val(txtMaxDrawDown.Text))
        ProgressBar1.Width = ProgressBar1.Width - (ProgressBar1.Width * Progress)
        DoEvents
    Loop

  4. #4
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Progress should be a number - an intger or long. I don't know all your variables or calculations. Here's a simple example of a progress bar.

    VB Code:
    1. Dim lMinVal As Single
    2. Dim lMaxVal As Single
    3.  
    4. lMinVal = 20
    5. lMaxVal = 1000
    6.  
    7. ProgressBar1.Min = lMinVal
    8. ProgressBar1.Max = lMaxVal
    9.  
    10. Do While lMinVal < lMaxVal
    11.     lMaxVal = lMaxVal - 1
    12.     ProgressBar1.Value = lMinVal + (ProgressBar1.Max - lMaxVal)
    13. Loop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width