+ Reply to Thread
Results 1 to 5 of 5

Userfor VBA code update

  1. #1
    Forum Contributor
    Join Date
    04-02-2013
    Location
    Hollywood, Fl
    MS-Off Ver
    Excel 2010
    Posts
    110

    Userfor VBA code update

    Hello all,
    I just discovered something while testing a userform within an Excel spreadsheet I'm working on that Stnkynts was nice enough to help me with. The userform searches through my data tab for specific records in order to edit them. While testing, I created multiple records using the same Unique ID. Now when I enter the ID in order to pull back the records, I am only retrieving the first record with that ID, the other records below that first one are not being retrieved using the userform. I know I have to enter a loop within my script so the search command button will go to the next record. When I attempted to enter a loop line into the script I can see the code is looping, but a new record isn't coming back into the userform, and my cursor appears to just cycle endlessly. What am I missing that will allow the userform to bring back the next record with the same record ID without cycling endlessly yet bringing nothing back? I've pasted the code I have, and I've also attached an example of the userform and the records I am attempting to retrieve. Thank you for any assistance.

    Damian37

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userfor VBA code update

    Hi

    I question whether you should be looping through your records merely to edit them. Looping should be the last resort since it's inherently slow and inefficient. Filtering data is the fastest way I know of doing this sort of stuff.

    So instead use a simple Advanced Data Filter to filter your data 'InPlace' so that only your required records are visible. Then use the .SpecialCells(xlCellTypeVisible) to identify these filtered cells and edit the cells as appropriate.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    04-02-2013
    Location
    Hollywood, Fl
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Userfor VBA code update

    Quote Originally Posted by Richard Buttrey View Post
    Hi

    I question whether you should be looping through your records merely to edit them. Looping should be the last resort since it's inherently slow and inefficient. Filtering data is the fastest way I know of doing this sort of stuff.

    So instead use a simple Advanced Data Filter to filter your data 'InPlace' so that only your required records are visible. Then use the .SpecialCells(xlCellTypeVisible) to identify these filtered cells and edit the cells as appropriate.
    This can be done within a userform? Currently I input a record number into my userform, and the form returns all fields associated with that record. If I use advanced data filter within my code, will it allow me to click on the search button until my desired record appears?

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Userfor VBA code update

    I was merely suggesting that rather than loop through individual records one at a time to incorporate them in a user form that you first grab all the data and if necessary load the lot in one go.

    I would however question whether it's more efficient to use a user form or just control the way the user edits the relevant rows on the data sheet itself.
    I tend to prefer using standard Excel functionality in the first instance if it's reasonable and acceptable to do so rather than starting with VBA as the solution.

  5. #5
    Forum Contributor
    Join Date
    04-02-2013
    Location
    Hollywood, Fl
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Userfor VBA code update

    Quote Originally Posted by Richard Buttrey View Post
    I was merely suggesting that rather than loop through individual records one at a time to incorporate them in a user form that you first grab all the data and if necessary load the lot in one go.

    I would however question whether it's more efficient to use a user form or just control the way the user edits the relevant rows on the data sheet itself.
    I tend to prefer using standard Excel functionality in the first instance if it's reasonable and acceptable to do so rather than starting with VBA as the solution.
    Hi Richard,
    I see what you're saying, unfortunately we're dealing with users that have a tendency to go in an make changes to fields they aren't supposed to make changes to. Therefore, we are trying to make it so they are forced to use a userform giving us the ability to hide the data tab, thus preventing them from making any unnecessary changes to the raw data being entered in.

+ 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. [SOLVED] VB Code help to change/update existing code
    By JDobbsy1987 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-24-2013, 04:46 PM
  2. Replies: 0
    Last Post: 10-15-2012, 04:43 PM
  3. Can background color of frame change on userform by combobox selection on userfor
    By teacher_rob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-12-2011, 05:47 PM
  4. Replies: 0
    Last Post: 04-21-2011, 09:20 AM
  5. [SOLVED] Call Userfor and click button with macro
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2005, 01:06 PM

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