ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Evaluate and execute a string (https://www.excelbanter.com/excel-programming/336394-evaluate-execute-string.html)

Randall[_6_]

Evaluate and execute a string
 
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!



Bernie Deitrick

Evaluate and execute a string
 
Use the controls collection, along the lines of

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

HTH,
Bernie
MS Excel MVP


"Randall" wrote in message
...
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!





Toppers

Evaluate and execute a string
 
Try:

UserForm1.ListBox2.AddItem Me.Controls(strCompName).Text

HTH


"Randall" wrote:

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!




Randall[_6_]

Thank you!!
 
Thanks for both replies--"Controls" does exactly what I was looking for!


"Randall" wrote in message
...
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!






All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com