+ Reply to Thread
Results 1 to 8 of 8

Excel slows and grows larger with every use of VBA.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2016
    Location
    Portsmouth, England
    MS-Off Ver
    2010
    Posts
    4

    Excel slows and grows larger with every use of VBA.

    I'm currently working on a spreadsheet that is designed so that the user can not alter any data without using a UserForm that automatically time, name and reason stamps the changes.
    In order to do this I created a UserForm that copies the entry that needs to be changed into a hidden spreadsheet and makes the changes before copying it back to the master sheet. The code does initially work, however, the problem is every time I use the userform, excel gets slower and increases in size until it becomes unusable. (The size and speed stay as they are despite saving, closing and reopening) I originally thought it could be a clipboard issue due to the copying and pasting but added in code to wipe the clipboard after every paste event, although this doesn't explain why the speed remains slow even after the programme is reopened. I've checked the end cells and they are correctly at the end of my used range. I also stopped auto calculations and all that good stuff but to no avail.
    Unfortunately I am on a workplace computer and do not have access rights to see if its a third party programme causing it, although I don't understand how it would effect the size of the spreadsheet if it was.

    All userforms which have this problem share a similar code but it seems to be the following which is the problem. (Though I seem to have successfully used it on another spreadsheet)

    The copy to the hidden sheet:
    Set rngA = Range("B1", Range("B5000").End(xlup))
    For Each cell In rngY
    If cell.Value = Sheets("Info").Range("B18") Then
    cell.EntireRow.Copy Worksheets("Info").Range("A32")
    End If
    Next cell
    Or the copy back to the master sheet:
    Set rngY = Range("B1", Range("B5000").End(xlup))
    For Each cell In rngY
    If cell.Value = Sheets("Info").Range("B18") Then
    cell.EntireRow.Select
    Sheets("Info").Range("A32:L32").Copy Destination:=ActiveCell
    End If
    Next cell

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,346

    Re: Excel slows and grows larger with every use of VBA.

    Set rngA = Range("B1", Range("B5000").End(xlup))
    I guess the A is a typo and must be a Y

    Secondly do you have to copy entire row to sheet Info?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    08-10-2016
    Location
    Portsmouth, England
    MS-Off Ver
    2010
    Posts
    4

    Re: Excel slows and grows larger with every use of VBA.

    Sorry, yes the A is a typo, whilst typing the code in on here.
    The entire range does not need to be selected just columns A:L, however, I'm a newbie at VBA and wouldn't know how to just select that range.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,346

    Re: Excel slows and grows larger with every use of VBA.

    Something like this.
    cell.offset(,-1).resize(,12).Copy Worksheets("Info").Range("A32")

  5. #5
    Registered User
    Join Date
    08-10-2016
    Location
    Portsmouth, England
    MS-Off Ver
    2010
    Posts
    4

    Re: Excel slows and grows larger with every use of VBA.

    Although your code does work, the problem still persists. The spread sheet grows significantly in size and time taken to complete the macro the more it is used.
    The spread sheet has grown from 478KB to 1.42MB from simply using the macro 4 times.
    All the macro does is copy the entry to a hidden sheet, amend some of the data and copy it back over.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,346

    Re: Excel slows and grows larger with every use of VBA.

    Without the copy-event.
    Worksheets("Info").Range("A32").resize(,12).value = cell.offset(,-1).resize(,12).Value
    And how does rest of your userform code looks like?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,346

    Re: Excel slows and grows larger with every use of VBA.

    Without the copy-event.
    Worksheets("Info").Range("A32").resize(,12).value = cell.offset(,-1).resize(,12).Value
    And how does rest of your userform code looks like?

  8. #8
    Registered User
    Join Date
    08-10-2016
    Location
    Portsmouth, England
    MS-Off Ver
    2010
    Posts
    4

    Re: Excel slows and grows larger with every use of VBA.

    Ok so the process is split into 3 parts.
    The user needs to first identify the entry that they need to view which is:

    Sub RLUOKButton_Click()
    
    Sheet7.Range("A43") = RLULNTB.Value
    Sheet7.Range("B43") = RLUIRNTB.Value
    
    If RLUIRNTB.Value <> "" Then
    
    'IRN Duplication'
    Dim n As Range
    Set n = [b:b].Find(RLUIRNTB.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not n Is Nothing And RLUIRNTB <> "" Then
    
    Unload Me
    
    ReviewUserForm.Show
    
    Else
    
    Cancel = True
    RLUIRNTB.Value = ""
    CreateObject("WScript.Shell").Popup _
    "This IRN is unrecognised.", 2, "Error"
    End If
    
    Else
    If RLULNTB.Value <> "" Then
    
    Dim m As Range
    Set m = [a:a].Find(RLULNTB.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not m Is Nothing And RLULNTB <> "" Then
    
    Unload Me
    
    ReviewUserForm.Show
    
    
    Else
    
    Cancel = True
    RLULNTB.Value = ""
    CreateObject("WScript.Shell").Popup _
    "This Local Number is unrecognised.", 2, "Error"
    End If
    
    Else
    CreateObject("WScript.Shell").Popup _
    "Please enter a Local Number or IRN.", 2, "Error"
    
    End If
    End If
    End Sub
    After that, the data review page will appear where users can view the data and make minor amendments if needed:

    Private Sub UserForm_Initialize()
    
    Set rngR = Range("B1", Range("B5000").End(xlUp))
    Set rngE = Range("A1", Range("A5000").End(xlUp))
    
    If Sheets("Info").Range("A43").Value <> "" Then
    
    For Each cell In rngE
    If cell.Value = Sheets("Info").Range("A43") Then
    cell.Resize(, 13).Copy Worksheets("Info").Range("A47")
    Application.CutCopyMode = False
    Call ClearClipboard
    Exit For
    End If
    Next cell
    
    Else
    
    For Each cell In rngR
    If cell.Value = Sheets("Info").Range("B43") Then
    cell.Offset(, -1).Resize(, 12).Copy Worksheets("Info").Range("A47")
    Application.CutCopyMode = False
    Call ClearClipboard
    Exit For
    End If
    Next cell
    End If
    
    
    RLNTB.Value = Sheets("Info").Range("A47").Value
    RIRNTB.Value = Sheets("Info").Range("B47").Value
    RDateTB.Value = Sheets("Info").Range("C47").Value
    RDateTB = Format(Sheets("Info").Range("C47").Value, "dd/mm/yyyy")
    RUnitTB.Value = Sheets("Info").Range("D47").Value
    ROffTB.Value = Sheets("Info").Range("E47").Value
    RSusTB.Value = Sheets("Info").Range("F47").Value
    RExTB.Value = Sheets("Info").Range("G47").Value
    RSSHTB.Value = Sheets("Info").Range("H47").Value
    
    
    RPriorityTB.Value = Sheets("Info").Range("I47").Value
    With RPriorityTB
    If RPriorityTB.Value = "Normal" Then
    .AddItem "Priority"
    .AddItem "Immediate"
    Else
    If RPriorityTB.Value = "Priority" Then
    .AddItem "Normal"
    .AddItem "Immediate"
    Else
    .AddItem "Normal"
    .AddItem "Priority"
    End If
    End If
    End With
    
    
    
    RStatusTB.Value = Sheets("Info").Range("J47").Value
    With RStatusTB
    If RStatusTB.Value = "Awaiting Ingestion" Then
    .AddItem "Ingestion"
    .AddItem "Analysis"
    .AddItem "Awaiting Archive"
    .AddItem "Archive"
    Else
    If RStatusTB.Value = "Ingestion" Then
    .AddItem "Awaiting Ingestion"
    .AddItem "Analysis"
    .AddItem "Awaiting Archive"
    .AddItem "Archive"
    Else
    If RStatusTB.Value = "Analysis" Then
    .AddItem "Awaiting Ingestion"
    .AddItem "Ingestion"
    .AddItem "Awaiting Archive"
    .AddItem "Archive"
    Else
    If RStatusTB.Value = "Awaiting Archive" Then
    .AddItem "Awaiting Ingestion"
    .AddItem "Ingestion"
    .AddItem "Analysis"
    .AddItem "Archive"
    Else
    .AddItem "Awaiting Ingestion"
    .AddItem "Ingestion"
    .AddItem "Analysis"
    .AddItem "Awaiting Archive"
    End If
    End If
    End If
    End If
    End With
    
    RCommentsTB.Value = Sheets("Info").Range("K47").Value
    RAddCommentsTB.Value = ""
    RDateLogTB.Value = Sheets("Info").Range("L47").Value
    
    End Sub
    
    
    Sub ReviewCancelButton_Click()
    Unload Me
    End Sub
    
    Sub ReviewSaveButton_Click()
    
    If RSSHTB.Value = Sheets("Info").Range("H47").Value Then
    Sheets("Info").Range("C50").Value = ""
    Else
    Sheets("Info").Range("C50").Value = RSSHTB.Value
    End If
    
    If RPriorityTB.Value = Sheets("Info").Range("I47").Value Then
    Sheets("Info").Range("D50").Value = ""
    Else
    Sheets("Info").Range("D50").Value = RPriorityTB.Value
    End If
    
    If RStatusTB.Value = Sheets("Info").Range("J47").Value Then
    Sheets("Info").Range("E50").Value = ""
    Else
    Sheets("Info").Range("E50").Value = RStatusTB.Value
    End If
    
    If RAddCommentsTB.Value = "" Then
    Sheets("Info").Range("F50").Value = ""
    Else
    Sheets("Info").Range("F50").Value = RAddCommentsTB.Value
    End If
    
    If Sheets("Info").Range("C50").Value = "" And Sheets("Info").Range("D50").Value = "" And Sheets("Info").Range("E50").Value = "" And Sheets("Info").Range("F50").Value = "" Then
    CreateObject("WScript.Shell").Popup _
    "No changes have been made.", 2, "Error"
    Else
    
    Sheets("Info").Range("B50").Value = Now
    
    Unload Me
    
    ReviewNameUserForm.Show
    End If
    
    End Sub
    From there, any amendments made will need to authorised by entering your name:

    Sub ReviewNameSaveButton_Click()
    'Unprotect'
     With ActiveSheet
                 
                .Unprotect Password:=""
                .Cells.Locked = False
                End With
                
                
    'Priority'
    If Sheets("Info").Range("D50").Value = "Normal" Then
    Sheets("Info").Range("I47").Value = "Normal"
     Sheets("Info").Range("D51").Value = "Priority changed to Normal: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
     If Sheets("Info").Range("D50").Value = "Priority" Then
     Sheets("Info").Range("I47").Value = "Priority"
     Sheets("Info").Range("D51").Value = "Priority changed to Priority: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
    If Sheets("Info").Range("D50").Value = "Immediate" Then
    Sheets("Info").Range("I47").Value = "Immediate"
     Sheets("Info").Range("D51").Value = "Priority changed to Immediate: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
      Sheets("Info").Range("D51").Value = ""
      End If
      End If
      End If
      
     'Status'
     If Sheets("Info").Range("E50").Value = "Awaiting Ingestion" Then
     Sheets("Info").Range("J47").Value = "Awaiting Ingestion"
     Sheets("Info").Range("E51").Value = "Status changed to Awaiting Ingestion: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
      If Sheets("Info").Range("E50").Value = "Ingestion" Then
      Sheets("Info").Range("J47").Value = "Ingestion"
     Sheets("Info").Range("E51").Value = "Status changed to Ingestion: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
      If Sheets("Info").Range("E50").Value = "Analysis" Then
      Sheets("Info").Range("J47").Value = "Analysis"
     Sheets("Info").Range("E51").Value = "Status changed to Analysis: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
      If Sheets("Info").Range("E50").Value = "Awaiting Archive" Then
      Sheets("Info").Range("J47").Value = "Awaiting Archive"
     Sheets("Info").Range("E51").Value = "Status changed to Awaiting Archive: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
      If Sheets("Info").Range("E50").Value = "Archive" Then
      Sheets("Info").Range("J47").Value = "Archive"
     Sheets("Info").Range("E51").Value = "Status changed to Archive: " & Sheets("Info").Range("B50").Value & ": " & ReviewNameTB.Value & Chr(10)
     Else
     Sheets("Info").Range("E51").Value = ""
     End If
     End If
     End If
     End If
     End If
     
     'Comments'
     If Sheets("Info").Range("F50").Value = "" Then
     Else
     Sheets("Info").Range("J51").Value = Sheets("Info").Range("K47").Value
     Sheets("Info").Range("K51").Value = Sheets("Info").Range("B50").Value & ": Comments by: " & ReviewNameTB.Value & Chr(10) & Sheets("Info").Range("F50").Value & Chr(10) & Chr(10) & Sheets("Info").Range("J51").Value
     Sheets("Info").Range("K47").Value = Sheets("Info").Range("K51").Value
     End If
     
     
     'Date Log'
     Sheets("Info").Range("G51").Value = Sheets("Info").Range("L47").Value
     Sheets("Info").Range("F51").Value = Sheets("Info").Range("C51").Value & Sheets("Info").Range("D51").Value & Sheets("Info").Range("E51").Value
     Sheets("Info").Range("L47").Value = Sheets("Info").Range("F51").Value & Sheets("Info").Range("G51").Value
    
    'Make changes to master sheet'
    Sheets("Master").Select
    
    Set rngG = Range("B1", Range("B5000").End(xlUp))
    For Each cell In rngG
    If cell.Value = Sheets("Info").Range("B47") Then
    cell.EntireRow.Select
    Sheets("Info").Range("A47:L47").Copy Destination:=ActiveCell
    Application.CutCopyMode = False
    Call ClearClipboard
    Exit For
    End If
    Next cell
    
    Unload Me
    
    
    With ActiveSheet
                 
                Cells.Locked = True
                .Protect Password:=""
                End With
    
    ReviewUserForm.Show
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 13
    Last Post: 07-07-2015, 12:09 PM
  2. [SOLVED] Graph grows as data grows
    By butlerar in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 01-31-2014, 06:56 PM
  3. Replies: 0
    Last Post: 05-18-2011, 07:43 AM
  4. Changing screen resolution - combo box size grows larger/smaller
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2010, 06:50 AM
  5. Excel file size grows when copied
    By EsAssistant in forum Excel General
    Replies: 2
    Last Post: 12-10-2010, 05:53 AM
  6. one colomn grows as another one grows?
    By doctorteeth in forum Excel General
    Replies: 0
    Last Post: 07-28-2010, 06:37 AM
  7. openoffice sheet to excel: grows considerably
    By Erik in forum Excel General
    Replies: 2
    Last Post: 01-15-2005, 01:06 PM

Tags for this Thread

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