Optimization VBA code

  • PHP

    Hi folks,


    I have a vba code that uses data from a huge spreadsheet "RAW" (more then 5000 rows and 50 columns) and generate data in another spreadsheet "Burndown (filter)"


    This code is taking long long time to be executed, and i need to use it lot of times, so it is not teffecient at all to keep it like this.
    Following is my code, and let the gurus play [Blocked Image: http://www.mrexcel.com/forum/images/smilies/icon_wink.gif]


    [PT]Sub Month_1()


    Sheets("RAW").Select
    Dim rawlastline As Integer
    Dim i As Integer
    Dim x As Integer
    Dim cell As Integer


    rawlastline = 2
    Do While Cells(rawlastline + 1, 1).Value <> ""



    rawlastline = rawlastline + 1
    Loop


    For x = 2 To 13


    cell = 0


    i = 2
    Do Until i = rawlastline
    If Sheets("RAW").Rows(i).Hidden = False Then
    If Month(Sheets("raw").Cells(i, 2)) = Month(Sheets("Burndown (filter)").Cells(1, x)) Then



    cell = cell + 1


    Sheets("Burndown (filter)").Select


    Cells(7, x).Value = cell




    End If
    End If


    i = i + 1
    Loop


    Next


    For x = 2 To 13


    cell = 0


    i = 2
    Do Until i = rawlastline
    If Sheets("RAW").Rows(i).Hidden = False Then
    If Sheets("raw").Cells(i, 18) <> "#" Then


    If Month(Sheets("raw").Cells(i, 18)) = Month(Sheets("Burndown (filter)").Cells(1, x)) Then


    ' DoEvents


    cell = cell + 1


    Sheets("Burndown (filter)").Select


    Cells(6, x).Value = cell




    End If
    End If


    End If


    i = i + 1
    Loop


    Next
    For x = 2 To 13




    i = 2


    Do Until i = rawlastline
    If Sheets("RAW").Rows(i).Hidden = False Then
    Sheets("raw").Select


    x = x + 49
    Sheets("raw").Select



    If Not Cells(i, x).Value = "" Then



    If Sheets("raw").Cells(i, x).Value <= 30 And Sheets("raw").Cells(i, x).Value <> 0 Then


    'DoEvents




    Sheets("Burndown (filter)").Select


    x = x - 49


    Cells(2, x).Value = Cells(2, x).Value + 1


    x = x + 49


    ElseIf Sheets("raw").Cells(i, x).Value > 30 And Sheets("raw").Cells(i, x).Value <= 60 Then
    Sheets("Burndown (filter)").Select
    x = x - 49


    Cells(3, x).Value = Cells(3, x).Value + 1


    x = x + 49


    ElseIf Sheets("raw").Cells(i, x).Value > 60 And Sheets("raw").Cells(i, x).Value <= 90 Then
    Sheets("Burndown (filter)").Select
    x = x - 49
    Cells(4, x).Value = Cells(4, x).Value + 1


    x = x + 49
    ElseIf Sheets("raw").Cells(i, x).Value > 90 Then
    Sheets("Burndown (filter)").Select


    x = x - 49
    Cells(5, x).Value = Cells(5, x).Value + 1
    End If


    End If


    End If


    i = i + 1
    If x > 14 Then
    x = x - 49
    End If


    Loop



    Next
    'Application.ScreenUpdating = True


    End Sub




    [/PT]THANK YOU IN ADVANCE !!

  • Re: Optimization VBA code


    EDIT: Please use code tags or your topic will be deleted. Thanks.


    Here is the code :


  • Re: Optimization VBA code


    Hi test this on a COPY of your workbook


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!