+ Reply to Thread
Results 1 to 3 of 3

I want to loop an if statement so different textboxes in userform are included

  1. #1
    Registered User
    Join Date
    09-07-2022
    Location
    London, England
    MS-Off Ver
    Version 2208
    Posts
    2

    I want to loop an if statement so different textboxes in userform are included

    Hi,

    This is my first post and I'm a complete novice.

    I'm looking for help with the code I'm writing and I'm sure there's a way to streamline it but I don't know how.

    I have an if statement that checks specific textboxes in a userform (in the example below, the textbox names are "OneBedOneBNum" and "OneBedOneBArea") and depending on if they contain data or not, a message box is displayed or the data is transferred to a worksheet.

    Is there a way I can loop this code so that after running for the "OneBedOneBNum" and "OneBedOneBArea" textboxes, they're replaced with a list of other textboxes in the userform with names "TwoBedOneBNum" and "TwoBedOneBArea", "ThreeBedOneBNum" and "ThreeBedOneBArea" etc.?

    Would I have to change the textbox names to do this, or can I list them out for iterative replacement in the code?

    I only have 13 textboxes to do this with but I feel like learning how to do the best way other than tedious copy and pasting and writing out all the names will be beneficial in the future.

    Below is the code I'm talking about (note that "Accom" and "Htg" are the worksheet names):
    Please Login or Register  to view this content.
    Many thanks,

    Jack

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: I want to loop an if statement so different textboxes in userform are included

    I'm not 100% sure if I've picked this up correctly but are you basically saying that you will need to copy/paste that block of code and change fieldnames etc for each of your 13 types?

    If so then you could have that block as a function and pass in the details to get the answers returned eg

    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    09-07-2022
    Location
    London, England
    MS-Off Ver
    Version 2208
    Posts
    2

    Re: I want to loop an if statement so different textboxes in userform are included

    Thanks for taking the time to look at my query and respond. I'm sorry I don't quite understand how I can use the function, I'll elaborate a bit and hopefully you might be able to steer me in the right direction?

    That's pretty much right re: copy/pasting the block of code and changing fieldnames within it. I'll need to copy and paste the code and change the fieldnames (corresponding with the textbox names in the user form), MsgBox contents (corresponding with labels in the user form) and increase the row number by 1 in the excel sheet where the data is pasted. I've pasted three blocks of code below to show what what I need to change, and a picture of user form is that helps. Can this be streamlined with a function?
    Please Login or Register  to view this content.
    Attachment 795204

+ 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] 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
  2. Userform problem with Textboxes and IF Statement
    By Mariolockem in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2017, 02:44 AM
  3. [SOLVED] Problem running Excel loop with Userform textboxes and checkboxes
    By dentler in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2017, 01:59 PM
  4. [SOLVED] userForm loop that returns info back into cells (with some cells not included)
    By Sleepyshy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-13-2012, 12:04 PM
  5. Write If/And statement for userform textboxes that are only visible
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-15-2012, 11:10 AM
  6. Loop into TextBoxes in an UserForm
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2010, 09:38 AM
  7. Need a macro to loop evaluation of many textboxes in a UserForm.
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-24-2006, 10:35 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