listbox items to string with offset

skacutter

New Member
Joined
Dec 23, 2016
Messages
18
Hello Mr Excel,

I am trying to bounce each value in a listbox against a column in another sheet to match the value then extract email address from another column. I am using code borrowed from the web and adapting it slightly. We are getting (Runtime error 91; Object variable or with block variable not set) on the second line. we do not know how strEmail or strTo should be declared but we have tried with strEmail set as range and strTo set as string. The code is picking up the first item in the listbox and selecting the correct sheet and column to match against. what might we be doing wrong with " Set strEmail = ws.Range("A:A").Find(What:=ListBox1.List(i), LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)"



For i = 0 To ListBox1.ListCount - 1
Set strEmail = ws.Range("A:A").Find(What:=ListBox1.List(i), LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
strTo = strTo & ";" & strEmail.Offset(0, 2).Value
Next i


we used this post to construct >> Excel VBA - How to insert ListBox Values to a string? - Stack Overflow
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
At a quick glance, is ws. defined further up in the code? ws. is either a sheet or a workbook right? (thus an Object)
Secondly, a form is also an object
ListBox1.List may need to have the userform included, such as Userform1.Listbox1.List
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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