Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vba - UserFrom with textbox

Posted on 2011-09-18
3
260 Views
Last Modified: 2012-05-12
Hello Experts,

I have a Userform that is composed of 4 textboxes - Each textbox is named Manager1, Manager2 etc. My data is on sheet("INFO"). I am having problems getting it to initiliaze.  Can you tell me where I am making my error.  Thanks.

Here is my code:

---------------------------------------

Private Sub UserForm_Initialize()
 
   Dim i As Integer
   Dim ctl As Control
   
   i = 1
   For Each ctl In UserForm1
      If textbox.Name = "Manager" & i Then
         textbox.text = Worksheets("INFO").Range("A" & i + 1).Value
         i = i + 1
      End If
   Next
   
End Sub
0
Comment
Question by:mike637
3 Comments
 
LVL 6

Expert Comment

by:bartvd
ID: 36556448
You need to change textbox in ctl
0
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
ID: 36556449
Why is the variable named ctl in your for each-statement and textbox when you use it inside the loop?
But this won't work reliable if for each iterates through the controls in wrong order. You can try this
   For Each ctl In UserForm1.Controls
      If left(ctl.Name, 7) = "Manager" Then
         ctl.Text = Worksheets("INFO").Range("A" & (Mid(ctl.Name, 8) + 1)).Value
      End If
   Next

Open in new window

Maybe you need Mid(ctl.Name, 7) instead of 8, not sure about VBA
0
 

Author Closing Comment

by:mike637
ID: 36556482
Thanks for the guidance!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question