+ Reply to Thread
Results 1 to 4 of 4

Problem running Excel loop with Userform textboxes and checkboxes

  1. #1
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Question Problem running Excel loop with Userform textboxes and checkboxes

    I know that the following code works when detecting if a text box has either a 0 value or is blank it makes the checkbox invisible. If it contains any value greater than 0 then it becomes visible:

    If (UserForm5.TextBox101.Text) = "" Then
    UserForm5.CheckBox21.Visible = False
    ElseIf (UserForm5.TextBox101.Text) = 0 Then
    UserForm5.CheckBox21.Visible = False
    Else
    UserForm5.CheckBox21.Visible = True
    End If

    The problem is I have many Textboxes and Checkboxes and I was trying to right a Loop code that would reduce the lines of code required to turn many on, so I have tried the following in a sub routine many different way and can not get it to work:

    Sub CheckBoxSetup()

    Dim Count, CkBoxNum, TxBoxNum As Long
    Dim TxStr, CkStr As String



    Count = 0
    CkBoxNum = 21
    TxBoxNum = 101

    TxStr = ("(UserForm5.TextBox" & TxBoxNum & ".Text)")
    'MsgBox (TxStr)
    CkStr = ("UserForm5.CheckBox" & CkBoxNum & ".Visible")
    'MsgBox (CkStr)

    Do Until Count = 20

    TxStr = ("(UserForm5.TextBox" & TxBoxNum & ".Text)")
    'MsgBox (TxStr)
    CkStr = ("UserForm5.CheckBox" & CkBoxNum & ".Visible")
    'MsgBox (CkStr)

    If TxStr = "" Then
    CkStr = False
    ElseIf TxStr = 0 Then
    CkStr = False
    Else
    CkStr = True
    End If

    CkBoxNum = CkBoxNum + 1
    TxBoxNum = TxBoxNum + 1
    Count = Count + 1

    Loop

    UserForm5.Show

    End Sub

    When enabling the MsgBoxes it does show the same strings but it does not work. Any help would be greatly appreciated.

    On another note, How do I mark a post, Solved?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Problem running Excel loop with Userform textboxes and checkboxes

    Try this (not tested).

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    01-08-2017
    Location
    Salt Lake City, Ut.
    MS-Off Ver
    2019 and 365
    Posts
    135

    Re: Problem running Excel loop with Userform textboxes and checkboxes

    AlphaFrog,

    Thank you so much. That works great.

    Dan

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Problem running Excel loop with Userform textboxes and checkboxes

    You're welcome.

    You can mark this as solved using the Thread Tools just above post #1.

+ 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] Code for all TextBoxes; Comboboxes and CheckBoxes in an UserForm
    By pipoliveira in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2016, 05:19 AM
  2. [SOLVED] How to loop through CheckBoxes on UserForm
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2014, 03:39 AM
  3. [SOLVED] Userform textboxes to populate with Cell data and sum if checkboxes ticked
    By RichardJSigKits in forum Excel General
    Replies: 12
    Last Post: 04-23-2014, 05:29 AM
  4. Loop into TextBoxes in an UserForm
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2010, 09:38 AM
  5. Loop through Checkboxes in a UserForm
    By PeterWilliams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2007, 09:22 PM
  6. 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