?
Solved

vba - UserFrom with textbox

Posted on 2011-09-18
3
Medium Priority
?
264 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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 article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

801 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