Solved

vba - UserFrom with textbox

Posted on 2011-09-18
3
254 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
Comment Utility
You need to change textbox in ctl
0
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
Comment Utility
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
Comment Utility
Thanks for the guidance!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now