+ Reply to Thread
Results 1 to 10 of 10

how to loop throughout specific sheets on userform instead of one sheet

  1. #1
    Forum Contributor
    Join Date
    12-02-2020
    Location
    Asia
    MS-Off Ver
    2010 (Windows 10 64-bit)
    Posts
    826

    how to loop throughout specific sheets on userform instead of one sheet

    Hi,
    I would change code to make it loop throughout sheets("PURCHASE","MAIN","DATA")
    instead of sheet one is "PURCHASE" as show in this line
    Please Login or Register  to view this content.
    here is whole code
    Please Login or Register  to view this content.
    thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,227

    Re: how to loop throughout specific sheets on userform instead of one sheet

    It's not clear what you want to do. This line of code is in UserForm_Activate, which is executed once when the form is first loaded. All it does is assign to the variable a a value taken from the sheet. If you loop through three sheets, the result is going to be that a has the value from sheet DATA. This defeats the purpose of using a loop.

    Please give us a more complete explanation of what you want to do, instead of what you think the code should be.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,879

    Re: how to loop throughout specific sheets on userform instead of one sheet

    But this code:
    Please Login or Register  to view this content.
    is called during the activation of the form, and then values of the array a are used during actions after chcnging any of 3 textboxes to fill the Listbox with "modified" content of Purchase sheet (at the moment)..

    So ... how this looping shall be used - may be it shall be located within FilterDAta procedure, not in form activation?
    Best Regards,

    Kaper

  4. #4
    Forum Contributor
    Join Date
    12-02-2020
    Location
    Asia
    MS-Off Ver
    2010 (Windows 10 64-bit)
    Posts
    826

    Re: how to loop throughout specific sheets on userform instead of one sheet

    when loop for three sheets I suppose to brings data from three sheets instead of one sheet.

    So ... how this looping shall be used - may be it shall be located within FilterDAta procedure, not in form activation?
    FilterDAta procedure depends on variable a where set is in UserForm_Activate so the change will be in UserForm_Activate.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,227

    Re: how to loop throughout specific sheets on userform instead of one sheet

    I see after reading Kaper's post that a is treated as an array elsewhere in the code. I focused on the line of code you pointed out. A comment on the Dim statement would be wise. Actually comments everywhere would be wise because your other variables have rather cryptic names.

    It is not clear how you want to populate the array. Your code references 1-7 as values for the second dimension of a. The line of code you showed will result in a two-dimensional array of values taken from the sheet, and it could be more than 7 rows. Also you will need three dimensions to do this for three sheets.

    I'll repeat that we need to know what you want to do.

  6. #6
    Forum Contributor
    Join Date
    12-02-2020
    Location
    Asia
    MS-Off Ver
    2010 (Windows 10 64-bit)
    Posts
    826

    Re: how to loop throughout specific sheets on userform instead of one sheet

    I'll repeat that we need to know what you want to do.
    actually I don't know what you want to know!
    all of sheets will be same structure what implement for one sheet as in original code should implement the others sheets.
    the code should populate data in listbox for 7 columns for all of sheets when write in textbox1,2,3 based on column 4,5,6 consecutively .

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,243

    Re: how to loop throughout specific sheets on userform instead of one sheet

    Posting a sample file will help.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: how to loop throughout specific sheets on userform instead of one sheet

    Give this a go.
    Please Login or Register  to view this content.
    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.

  9. #9
    Forum Contributor
    Join Date
    12-02-2020
    Location
    Asia
    MS-Off Ver
    2010 (Windows 10 64-bit)
    Posts
    826

    Re: how to loop throughout specific sheets on userform instead of one sheet

    perfect!
    thank you so much ,bakerman.
    thanks guys for trying to help me.

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

    Re: how to loop throughout specific sheets on userform instead of one sheet

    You're welcome and thanks for rep+.

+ 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] vba code to loop through several sheets and copy specific headers to summary sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-27-2024, 09:10 AM
  2. [SOLVED] how loop specific textboxes to sum the values on userform
    By ABDELFATTA in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-09-2022, 12:17 PM
  3. [SOLVED] Using Array to Loop through specific sheets - need to add sheet name
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2020, 06:21 PM
  4. [SOLVED] Userform List to Delete Sheets after specific sheet
    By Kevchenk0 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-07-2020, 07:43 AM
  5. Help: Looking for a For Loop to use with UserForm for Specific columns
    By John Forrestor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2018, 10:40 PM
  6. Help: Newbie Looking for help with UserForm For Loop for specific Columns
    By John Forrestor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2018, 10:39 PM
  7. [SOLVED] loop through specific comboboxes on userform
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2017, 02:52 AM

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