Adding values to an already existing array

earldunning

Active Member
Joined
Nov 9, 2006
Messages
263
Hello,
I have a list of UserIDs that I am grabbing as an array to populate a "To:" box in an email.

I have this all working except I want to add 2 more values to the array that are not in the list.

So what I have which works great is:

Code:
Dim vaRecipients As Variant

vaRecipients = Range("CRToIDList").Value  'this is my range for my standard mailing list

But what I want is
HTML:
vaRecipients = Range("CRToIDList").Value &  Range("E1").Value & Range("E2").Value

I am trying to pick up 2 more userIDs off the current form and add them to the standard list. I do not however want to add them permanently, only for the purpose of emailing. It errors when I try this. How do I add the 2 extra values to the end of the array? Do I need to count how many are in the original list and then increment? It seems like there should be an easy way to just add it to the end regardless.

Thoughts?
Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try something like

Code:
Dim myArr() As Variant, iLast As Integer
myArr = Range("A1:A5").Value
myArr = WorksheetFunction.Transpose(myArr)
iLast = UBound(myArr)

ReDim Preserve myArr(1 To iLast + 2)
myArr(iLast + 1) = Range("B1").Value
myArr(iLast + 2) = Range("B2").Value

This reads A1:A5 into the array, then adds B1 and B2.
 
Last edited:
Upvote 0
vaRecipients = Range("CRToIDList").Value
vaRecipients = WorksheetFunction.Transpose(vaRecipients)
iLast = UBound(vaRecipients) + 2
MsgBox (iLast)
ReDim Preserve vaRecipients(1 To iLast + 2)
vaRecipients(iLast - 1) = Range("E1").Value
vaRecipients(iLast) = Range("E2").Value


I think its working!

Thanks!!
 
Last edited:
Upvote 0
I realized that just after I posted and modified the post. You must have looked at it just after I posted. Your too quick!!!
Check above now. Does it look right?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,199
Messages
6,054,081
Members
444,702
Latest member
patrickmg17

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