Trouble expanding cell range in a vLookup in a macro

NoSuperUserHere

New Member
Joined
Sep 7, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi.

I have a macro that looks at a cell for a name, references another sheet and gets the email that corresponds to the name, and sends an email. I hopped into VBA and thought I entered the correct data to expand my vLookup. The original expression is:

Recipient = Application.VLookup(ActiveSheet.Range("A15").Value, Worksheets("List").Range("A2:B100"), 2, False)

I thought if I expanded the range like so:

Recipient = Application.VLookup(ActiveSheet.Range("A15:A17").Value, Worksheets("List").Range("A2:B100"), 2, False)

I could add more names below cell A15 and have the recipient be multiple people. It's not working. The "To" field is blank and the email doesn't get sent. What am I missing? Do I need to do an "and" statement? Would that look something like this:

Recipient = Application.VLookup(ActiveSheet.Range("A15").Value AND , Application.VLookup(ActiveSheet.Range("A16").Value AND , Application.VLookup(ActiveSheet.Range("A17").Value AND , Worksheets("List").Range("A2:B100"), 2, False)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I hadn't thought of that. So it would be something like this?

Recipient = Application.VLookup(ActiveSheet.Range("A15").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient = Application.VLookup(ActiveSheet.Range("A16").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient = Application.VLookup(ActiveSheet.Range("A17").Value, Worksheets("List").Range("A2:B100"), 2, False)
 
Upvote 0
How many potential recipients can there be?
is there always a recipient in A15, A16 and A17?
 
Upvote 0
easiest way I can see is to declare them seperately.

Dim Recipient1 as String (assuming this is how you have it declared)
Dim Recipient2 as String
Dim Recipient3 as String
Dim Recipient4 as String
Dim Recipient5 as String


Recipient1 = Application.VLookup(ActiveSheet.Range("A15").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient2 = Application.VLookup(ActiveSheet.Range("A16").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient3 = Application.VLookup(ActiveSheet.Range("A17").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient4 = Application.VLookup(ActiveSheet.Range("A18").Value, Worksheets("List").Range("A2:B100"), 2, False)
Recipient5 = Application.VLookup(ActiveSheet.Range("A19").Value, Worksheets("List").Range("A2:B100"), 2, False)
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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