Solved

vba - UserFrom with textbox

Posted on 2011-09-18
3
263 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
[X]
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
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

687 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