• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Userform populating incorrect number of TextBox

ThrottleWorks

Excel Ninja
Hi,

I am using below mentioned code to populate Textboxes through Userform.

For example if the value in cell B1 is 1, UF will show 1 Textbox, if the value is 3 UF will show 3 T.B. and so on.

My problem is, the value in cell B1 keeps changing. For example,
When I 1st run the macro, B1 value was 3, when I run the macro for second time, value in B1 is 1 but the macro will still show 3 Textboxes instead on 1.

And, this is not consistent also, suppose UF shows 3 T.B. and I know it should show 2 T.B then I close the userform manually and re-try.

On the re-try macro will show correct number for Textboxes.

Sorry for not uploading the file. Can anyone please help me in this.

Code:
BoxCnt = ThisWorkbook.Worksheets("Macro").Range("b1").Value


Code:
Private Sub UserForm_Initialize()

    If BoxCnt = 3 Then
        TextBox1.Value = ThisWorkbook.Worksheets("Macro").Range("a1").Value
        TextBox2.Value = ThisWorkbook.Worksheets("Macro").Range("a2").Value
        TextBox3.Value = ThisWorkbook.Worksheets("Macro").Range("a3").Value
    End If
  
    If BoxCnt = 2 Then
        TextBox1.Value = ThisWorkbook.Worksheets("Macro").Range("a1").Value
        TextBox2.Value = ThisWorkbook.Worksheets("Macro").Range("a2").Value
        TextBox3.Visible = False: cmd3.Visible = False
    End If
  
    If BoxCnt = 1 Then
        TextBox1.Value = ThisWorkbook.Worksheets("Macro").Range("a1").Value
        TextBox2.Visible = False: TextBox3.Visible = False
        cmd2.Visible = False: cmd3.Visible = False
    End If

End Sub
 
Last edited:
Test with following code inserted at start of Macro. It could be that the macro fires before cell change has completely registered.

Code:
Application.Wait(Now + TimeValue("00:00:01"))

Set time between 1 to 5 sec and see if it makes any difference.
 
Hi @Chihiro , thanks a lot for the help. Just realized the problem lies somewhere else.

Not able to identify yet however I am certain that the problem is not in the above mentioned code.

Will post the details shortly, have a nice day ahead. :)
 
Back
Top