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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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