Evaluate and execute a string

  • Thread starter Thread starter Randall
  • Start date Start date
R

Randall

I am trying to take the selected text from one listbox and add it to a
separate listbox. Something like this: UserForm1.lstEmployee.AddItem
(lstCompanyA.Text)

The problem is that the name of the listbox that I am taking from
(lstCompanyA) is contained within a string variable. So I have tried this:
Dim strTest As String
strTest = "UserForm1.lstEmployee.AddItem (" & strCompName & ".Text)"
Evaluate (strTest)

But I don't think I can do that using the Evaluate method. Is there other
way to do this?

Thanks in advance for any suggestions!
 
Use the controls collection, along the lines of

UserForm1.lstEmployee.AddItem UserForm1.Controls(strCompName).Text

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top