VBA Offset with multiselect list

OldManDemosthenes

New Member
Joined
Apr 19, 2011
Messages
38
I have created a userform with a multiselect listbox which is populated from sheet("Names"). When selected, and the "Run" button on the userform is clicked, the selections are placed in column D of sheet("Input"). (Code is below)

What I would like to do is add an offset formula (or whatever you think might work better) which will draw data from sheet("Data") about each selection and place it next to the selection on the Input sheet.

Specifically, if "name3" is selected in the listbox, the formula will find "name3" in column A of the Data sheet and find the value from the same row, column C of that sheet. It would then place that value found in row E of the Input sheet next to the "name3" value which is in column D. The formula would repeat this process for each of the listbox selections.

Thanks in advance

Private Sub cbRun_Click()
Dim i As Long​
Range("D:E").ClearContents​
With lbName​
For i = 0 To .ListCount - 1​
If .Selected(i) Then​
Cells(Rows.Count, "D").End(xlUp)(2) = .List(i)​
End If​
Next i​
End With​
Unload Me
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I tried using the vlookup function but can't get it to work.

Any ideas?

With lbName
For i = 0 To .ListCount - 1​
If .Selected(i) Then​
Cells(Rows.Count, "D").End(xlUp)(2) = .List(i)​
Cells(Rows.Count, "E").End(xlUp)(2) = _​
workbookfunction.VLookup(.List(i), _​
ActiveWorkbook.Sheets("Data").Range("A:C"), 3, False)​
End If​
Next i​
End With
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top