Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Waldemar Fischer   on Oct 27 In MS Office Category.

  
Question Answered By: Constance Reid   on Oct 27

To adjust your macro the least, try something on these lines:

For i = iRetCodeMin To iRetCodeMax
s = "iT_Legend" & i
Set sName = UserForm1.Controls(s)
sString = Application.WorksheetFunction.VLookup _
(i, Range("RetCodes_Lookup"), 3, False)
sName.Caption = sString
Next i

If it's only the caption  you're changing you can dispense with
creating an object  (sName) and the variable  's' thus:

For i = iRetCodeMin To iRetCodeMax
sString = Application.WorksheetFunction.VLookup _
(i, Range("RetCodes_Lookup"), 3, False)
UserForm1.Controls("iT_Legend" & i).Caption = sString
Next i

perhaps even shorter by dispensing with sString:

For i = iRetCodeMin To iRetCodeMax
UserForm1.Controls("iT_Legend" & i).Caption _
= Application.WorksheetFunction.VLookup _
(i, Range("RetCodes_Lookup"), 3, False)
Next i

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Setting UserForm captions via VBA loop Or get search suggestion and latest updates.


Tagged: