+ Reply to Thread
Results 1 to 2 of 2

Excel Form progress bar within macro problem

  1. #1
    Registered User
    Join Date
    03-04-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    1

    Excel Form progress bar within macro problem

    hi there,

    I am trying to run a progress bar based on moving an image within a form control whilst I am running a macro in the background. However, the form control prevents the rest of the macro from looping. I have tried using Unload Form to close the form until the macro loops back, but this doesn't work. I attach the draft code below. Can anyone help? Thanks alot!

    Sub Sales()
    '
    ' Sales Macro
    '

    '
    Dim sngPercent As Double
    Dim intMax As Integer
    Dim y As Integer


    y = Range("Start_year")
    intMax = Range("End_year") - Range("Start_year") + 1

    Do While y < Range("End_year") + 1

    ' progress bar
    Application.ScreenUpdating = True
    sngPercent = (y - Range("Start_year")) / intMax
    Load UserForm2
    UserForm2.Show
    UserForm2.Repaint
    UserForm2.imgXPMarker.Left = 50 + (UserForm2.labXPBackground.Width * sngPercent)
    Range("sng").Offset((y - 2011), 0) = sngPercent
    Application.ScreenUpdating = False
    UserForm2.Hide
    Unload UserForm2
    DoEvents

    ' main loop

    Sheets("Uptake Calculations").Select
    Range("Calculation_year") = y
    ActiveSheet.Calculate

    Range("Annual_sales").Select
    Range("Annual_sales").Copy

    Sheets("Annual Sales").Select

    Range("Output").Offset((y - 2011) * 12, 0).Select
    Range("Output").Offset((y - 2011) * 12, 0).PasteSpecial xlPasteValuesAndNumberFormats


    y = y + 1

    Loop

    Worksheets("Control").Select

    Application.ScreenUpdating = True

    '
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Excel Form progress bar within macro problem

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1