Excel VBA create a list from non-blank cells in range

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
56
Hi all,
I am trying to search for all non-blank cells in a range (let's say A1-A30) then with all non-blank values set a variable that is just a list of the cell values separated by a ";"

Essentially there will be email addresses in this list. Not all cells from A1-A30 will be populated, it's dependent on other circumstances to determine who should be getting the email (I've built this function out already). I'm just trying to wrap my head around how to search all non-empty cells and create a list of that separated by ";" so that I can then set that list as a variable.

Then with my coding for the email I could just call that variable in the .To section.

Any help on the best way to go about doing this would be greatly appreciated.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Are A1:A30 hard values, or formulae?
 
Upvote 0
In that case try
Code:
Sub jasonfish11()
   Dim Strg As String
   With Range("A1:A30")
      Strg = Replace(Application.Trim(Join(Application.Transpose(.Value), " ")), " ", ";")
   End With
   MsgBox Strg
End Sub
This assumes that the cells don't have any spaces in them.
 
Upvote 0
In that case try
Code:
Sub jasonfish11()
   Dim Strg As String
   With Range("A1:A30")
      Strg = Replace(Application.Trim(Join(Application.Transpose(.Value), " ")), " ", ";")
   End With
   MsgBox Strg
End Sub
This assumes that the cells don't have any spaces in them.

Since they are email addresses they will not. Thank you so much this is much easier than the road I was heading down and struggling with.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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