Closed Thread
Results 1 to 11 of 11

User form very slow to transfer data to worksheet

  1. #1
    Registered User
    Join Date
    01-14-2015
    Location
    New York
    MS-Off Ver
    2011
    Posts
    13

    User form very slow to transfer data to worksheet

    Hi,
    I've created a userform for data entry from a questionnaire. There is a save button which transfers all the information to the worksheet but this takes over 30 seconds to complete. I've tried to fiddle with suppressing events using EnableEvents but it does't help. I'm not sure what to do so any help would be really appreciated! Bellow is the whole userform code, most of the data transfer comes from checkboxes from 18 questions (I named them CB1E/G/A/P for excellent good average poor etc.)

    Public EnableEvents As Boolean

    Private Sub CancelButton_Click()
    Unload Me
    End Sub

    Private Sub ClearButton_Click()
    Call UserForm_Initialize
    End Sub

    Private Sub SaveButton_Click()

    Dim emptyRow As Long

    'Make Sheet1 active
    Sheet1.Activate

    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

    'Transfer information
    If Not EnableEvents Then Exit Sub

    Me.EnableEvents = False
    If CB1E.Value = True Then Cells(emptyRow, 1).Value = "4"
    If CB1G.Value = True Then Cells(emptyRow, 1).Value = "3"
    If CB1A.Value = True Then Cells(emptyRow, 1).Value = "2"
    If CB1P.Value = True Then Cells(emptyRow, 1).Value = "1"
    If CB2E.Value = True Then Cells(emptyRow, 2).Value = "4"
    If CB2G.Value = True Then Cells(emptyRow, 2).Value = "3"
    If CB2A.Value = True Then Cells(emptyRow, 2).Value = "2"
    If CB2P.Value = True Then Cells(emptyRow, 2).Value = "1"
    If CB3E.Value = True Then Cells(emptyRow, 3).Value = "4"
    If CB3G.Value = True Then Cells(emptyRow, 3).Value = "3"
    If CB3A.Value = True Then Cells(emptyRow, 3).Value = "2"
    If CB3P.Value = True Then Cells(emptyRow, 3).Value = "1"
    If CB4E.Value = True Then Cells(emptyRow, 4).Value = "4"
    If CB4G.Value = True Then Cells(emptyRow, 4).Value = "3"
    If CB4A.Value = True Then Cells(emptyRow, 4).Value = "2"
    If CB4P.Value = True Then Cells(emptyRow, 4).Value = "1"
    If CB5E.Value = True Then Cells(emptyRow, 5).Value = "4"
    If CB5G.Value = True Then Cells(emptyRow, 5).Value = "3"
    If CB5A.Value = True Then Cells(emptyRow, 5).Value = "2"
    If CB5P.Value = True Then Cells(emptyRow, 5).Value = "1"
    If CB6E.Value = True Then Cells(emptyRow, 6).Value = "4"
    If CB6G.Value = True Then Cells(emptyRow, 6).Value = "3"
    If CB6A.Value = True Then Cells(emptyRow, 6).Value = "2"
    If CB6P.Value = True Then Cells(emptyRow, 6).Value = "1"
    If CB7E.Value = True Then Cells(emptyRow, 7).Value = "4"
    If CB7G.Value = True Then Cells(emptyRow, 7).Value = "3"
    If CB7A.Value = True Then Cells(emptyRow, 7).Value = "2"
    If CB7P.Value = True Then Cells(emptyRow, 7).Value = "1"
    If CB8E.Value = True Then Cells(emptyRow, 8).Value = "4"
    If CB8G.Value = True Then Cells(emptyRow, 8).Value = "3"
    If CB8A.Value = True Then Cells(emptyRow, 8).Value = "2"
    If CB8P.Value = True Then Cells(emptyRow, 8).Value = "1"
    If CB9E.Value = True Then Cells(emptyRow, 9).Value = "4"
    If CB9G.Value = True Then Cells(emptyRow, 9).Value = "3"
    If CB9A.Value = True Then Cells(emptyRow, 9).Value = "2"
    If CB9P.Value = True Then Cells(emptyRow, 9).Value = "1"
    If CB10E.Value = True Then Cells(emptyRow, 10).Value = "4"
    If CB10G.Value = True Then Cells(emptyRow, 10).Value = "3"
    If CB10A.Value = True Then Cells(emptyRow, 10).Value = "2"
    If CB10P.Value = True Then Cells(emptyRow, 10).Value = "1"
    If CB11E.Value = True Then Cells(emptyRow, 11).Value = "4"
    If CB11G.Value = True Then Cells(emptyRow, 11).Value = "3"
    If CB11A.Value = True Then Cells(emptyRow, 11).Value = "2"
    If CB11P.Value = True Then Cells(emptyRow, 11).Value = "1"
    If CB12E.Value = True Then Cells(emptyRow, 12).Value = "4"
    If CB12G.Value = True Then Cells(emptyRow, 12).Value = "3"
    If CB12A.Value = True Then Cells(emptyRow, 12).Value = "2"
    If CB12P.Value = True Then Cells(emptyRow, 12).Value = "1"
    If CB13E.Value = True Then Cells(emptyRow, 13).Value = "4"
    If CB13G.Value = True Then Cells(emptyRow, 13).Value = "3"
    If CB13A.Value = True Then Cells(emptyRow, 13).Value = "2"
    If CB13P.Value = True Then Cells(emptyRow, 13).Value = "1"
    If CB14E.Value = True Then Cells(emptyRow, 14).Value = "4"
    If CB14G.Value = True Then Cells(emptyRow, 14).Value = "3"
    If CB14A.Value = True Then Cells(emptyRow, 14).Value = "2"
    If CB14P.Value = True Then Cells(emptyRow, 14).Value = "1"
    If CB15E.Value = True Then Cells(emptyRow, 15).Value = "4"
    If CB15G.Value = True Then Cells(emptyRow, 15).Value = "3"
    If CB15A.Value = True Then Cells(emptyRow, 15).Value = "2"
    If CB15P.Value = True Then Cells(emptyRow, 15).Value = "1"
    If CB16E.Value = True Then Cells(emptyRow, 16).Value = "4"
    If CB16G.Value = True Then Cells(emptyRow, 16).Value = "3"
    If CB16A.Value = True Then Cells(emptyRow, 16).Value = "2"
    If CB16P.Value = True Then Cells(emptyRow, 16).Value = "1"
    If CB17E.Value = True Then Cells(emptyRow, 17).Value = "4"
    If CB17G.Value = True Then Cells(emptyRow, 17).Value = "3"
    If CB17A.Value = True Then Cells(emptyRow, 17).Value = "2"
    If CB17P.Value = True Then Cells(emptyRow, 17).Value = "1"
    If CBYES.Value = True Then Cells(emptyRow, 18).Value = "Y"
    If CBNO.Value = True Then Cells(emptyRow, 18).Value = "N"

    Cells(emptyRow, 19).Value = CBmonth.Value
    Cells(emptyRow, 20).Value = TByear.Value
    Me.EnableEvents = True

    Call UserForm_Initialize
    End Sub

    Private Sub TByear_Enter()
    If Not EnableEvents Then Exit Sub
    Me.EnableEvents = False
    TByear.Value = ""
    Me.EnableEvents = True
    End Sub
    Private Sub UserForm_Initialize()

    Me.EnableEvents = True

    'Clear tickboxes'
    Dim ctrl As Control
    For Each ctrl In Me.Controls
    If TypeName(ctrl) = "CheckBox" Then ctrl.Value = False
    Next

    'Fill CBmonth'
    With Me.CBmonth
    .AddItem "January"
    .AddItem "February"
    .AddItem "March"
    .AddItem "April"
    .AddItem "May"
    .AddItem "June"
    .AddItem "July"
    .AddItem "August"
    .AddItem "September"
    .AddItem "October"
    .AddItem "November"
    .AddItem "December"
    .AddItem "Select Month"
    End With

    CBmonth.ListIndex = 12

    'Clear year'
    TByear.Value = "yyyy"

    End Sub

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User form very slow to transfer data to worksheet

    Have you tried
    Please Login or Register  to view this content.
    after the Dim EmptyRow as Long line?
    Be sure to change it back by adding an
    Please Login or Register  to view this content.
    line just before the End Sub line.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    01-14-2015
    Location
    New York
    MS-Off Ver
    2011
    Posts
    13

    Re: User form very slow to transfer data to worksheet

    Hi Tom,
    Thanks for the quick reply. I just tried this but I hasn't made any difference.

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User form very slow to transfer data to worksheet

    Hmm.....Sorry it made no difference.......that was the extent of my knowledge for speeding up VBA code.

  5. #5
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: User form very slow to transfer data to worksheet

    can you post the Workbook?
    that would make things easier.

    and put your Code in the first poste in Code Tags.
    Just Mark your Code and click the # button

    Greets
    Loki

  6. #6
    Registered User
    Join Date
    01-14-2015
    Location
    New York
    MS-Off Ver
    2011
    Posts
    13

    Re: User form very slow to transfer data to worksheet

    QUESTIONNAIRE.xlsm
    There is some data that i've just been adding to test the workbook.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: User form very slow to transfer data to worksheet

    Just add this at the beginning after

    Please Login or Register  to view this content.
    and in the end

    Please Login or Register  to view this content.
    The problem is not the userform its that excel calculates all your formulas every time you add a new value to the sheet.
    Also your tool does not prevent the user from giving 4 ratings for the same category.
    so if the user rates poor and excellent it will end up with poor cause that comes last in your if statements.
    Use option button groups to prevent that or write code that checks if only one hook is set for each group
    Last edited by LordLoki; 06-08-2015 at 11:07 AM.

  8. #8
    Registered User
    Join Date
    01-14-2015
    Location
    New York
    MS-Off Ver
    2011
    Posts
    13

    Re: User form very slow to transfer data to worksheet

    Finally! Thank you so much!

  9. #9
    Registered User
    Join Date
    02-07-2022
    Location
    Edmonton, Alberta
    MS-Off Ver
    365
    Posts
    2

    Re: User form very slow to transfer data to worksheet

    I was just having the same issues with my user form. Your solution worked for me as well!

    Thanks (almost 7 years later) lol

  10. #10
    Registered User
    Join Date
    02-07-2022
    Location
    Edmonton, Alberta
    MS-Off Ver
    365
    Posts
    2

    Re: User form very slow to transfer data to worksheet

    On second note it has prevented my pivot table from automatically refreshing.

    If you are still around or anyone here can help could you have a quick look maybe we can adjust something small. It seems the ScreenUpdating = False is what is stopping the pivot table from refreshing.


    Private Sub buylong4_Click()

    'General Variables
    Dim numRows As Long
    numRows = Range(Selection.ListObject.Name).Rows.Count

    Dim firstRow As Long
    firstRow = Range(Selection.ListObject.Name).Row

    Dim tableName As String
    tableName = Selection.ListObject.Name

    Set tbl = ActiveSheet.ListObjects(tableName)

    Dim x As Long

    'Speeds up User Form
    ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    '-----------------------------------------------------------------------------------------------------------------
    Dim currentRow As Long
    currentRow = firstRow - 1

    For x = 1 To tbl.Range.Rows.Count

    If WorksheetFunction.CountA(tbl.Range.Rows(x)) = 0 Then

    'Add the values to the table
    Worksheets("Trade Tape").Cells(currentRow, 4).Value = Now
    Worksheets("Trade Tape").Cells(currentRow, 5).Value = Date
    Worksheets("Trade Tape").Cells(currentRow, 6).Value = Ticker4.Value
    Worksheets("Trade Tape").Cells(currentRow, 7).Value = Qty4.Value
    Worksheets("Trade Tape").Cells(currentRow, 8).Value = "LONG"
    Worksheets("Trade Tape").Cells(currentRow, 9).Value = entryprice4.Value
    Worksheets("Trade Tape").Cells(currentRow, 10).Value = exitprice4.Value
    Worksheets("Trade Tape").Cells(currentRow, 11).Value = maxdrawdownprice4.Value
    Worksheets("Trade Tape").Cells(currentRow, 12).Value = maxdrawupprice4.Value
    'Change Price of trading fees here!!!
    Worksheets("Trade Tape").Cells(currentRow, 13).Value = 4.95 * 2
    Worksheets("Trade Tape").Cells(currentRow, 19).Value = Setupstyle4.Value
    Worksheets("Trade Tape").Cells(currentRow, 20).Value = rvalue4.Value

    Application.ScreenUpdating = True
    Unload Me
    Exit Sub

    End If

    currentRow = currentRow + 1

    Next x

    Dim endRow As Long
    endRow = firstRow + numRows


    'Find last row of table and adds a new row + resizes the table
    Cells(endRow, 1).EntireRow.Insert

    With tbl.Range
    tbl.Resize .Resize(.CurrentRegion.Rows.Count)
    End With

    'Add the values to the table
    Worksheets("Trade Tape").Cells(endRow, 4).Value = Now
    Worksheets("Trade Tape").Cells(endRow, 5).Value = Date
    Worksheets("Trade Tape").Cells(endRow, 6).Value = Ticker4.Value
    Worksheets("Trade Tape").Cells(endRow, 7).Value = Qty4.Value
    Worksheets("Trade Tape").Cells(endRow, 8).Value = "LONG"
    Worksheets("Trade Tape").Cells(endRow, 9).Value = entryprice4.Value
    Worksheets("Trade Tape").Cells(endRow, 10).Value = exitprice4.Value
    Worksheets("Trade Tape").Cells(endRow, 11).Value = maxdrawdownprice4.Value
    Worksheets("Trade Tape").Cells(endRow, 12).Value = maxdrawupprice4.Value
    'Change Price of trading fees here!!!
    Worksheets("Trade Tape").Cells(endRow, 13).Value = 4.95 * 2
    Worksheets("Trade Tape").Cells(endRow, 19).Value = Setupstyle4.Value
    Worksheets("Trade Tape").Cells(endRow, 20).Value = rvalue4.Value

    '------------INDICATES WHETHER STRATEGY WAS USED OR NOT------------

    If CheckBox1.Value = True Then
    Worksheets("Trade Tape").Cells(endRow, 18).Value = "Yes"
    End If

    If CheckBox1.Value = False Then
    Worksheets("Trade Tape").Cells(endRow, 18).Value = "No"
    End If

    Application.ScreenUpdating = True

    Sort
    Unload Me

    'Speeds up User Form (Continued)
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    End Sub

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: User form very slow to transfer data to worksheet

    Quote Originally Posted by Marc1919 View Post
    On second note it has prevented my pivot table from automatically refreshing.

    If you are still around or anyone here can help could you have a quick look maybe we can adjust something small. It seems the ScreenUpdating = False is what is stopping the pivot table from refreshing.
    ...


    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

    Also, please use code tags when posting code (see my foot note)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 12-29-2015, 06:35 AM
  2. Unable to transfer data from user form to spread sheet
    By katieshields in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2014, 05:43 AM
  3. Replies: 1
    Last Post: 08-28-2013, 05:04 PM
  4. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  5. User form data transfer in VBA
    By jrcream in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2008, 01:59 AM

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