Combine 2 var into 1 string with & in between

bumbum2812

New Member
Joined
Sep 7, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi Experts Please help me combine 2 var into 1 string with & in between.
My data is from A1:A2 & i have below code to put in MsgBox.

Rich (BB code):
 Sub abc() 
Dim lr3   As Long 
Dim var As Variant 
lr3 = Range("A" & Rows.Count).End(xlUp).Row 
For Each var In Sheets("Sheet1").Range("A1:A" & lr3)     
MsgBox var 
Next var
 End Sub

Any help will be so much apricated
 
Use
VBA Code:
If IsArray(Ary) Then .Subject ="Hello -"& Join(Ary, "&") Else .Subject= "Hello -" & Ary
Thank you so much, this will work if i move the code inside my sub to send email.
Good day to you Sir !
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Fluff,

Can you help to write a code like this in VBA & able to put in .subject for outlook & it can show apply for single Ary as well.

=IFS(LEN(Join(Ary, "&"))>200,"Multiple Jobs",LEN(Join(Ary, "&"))<200,Join(Ary, "&")
 
Upvote 0
How about
VBA Code:
   If IsArray(Ary) Then
      txt = Ary
   ElseIf Len(Join(Ary, "&")) > 200 Then
      txt = "Multiple jobs"
   Else
      txt = Join(Ary, "&")
   End If
   .Subject = txt
 
Upvote 0
How about
VBA Code:
   If IsArray(Ary) Then
      txt = Ary
   ElseIf Len(Join(Ary, "&")) > 200 Then
      txt = "Multiple jobs"
   Else
      txt = Join(Ary, "&")
   End If
   .Subject = txt
Hi, i replace this with yours but it returns blank.
If IsArray(Ary) Then .Subject ="Hello -"& Join(Ary, "&") Else .Subject= "Hello -" & Ary
 
Upvote 0
Is there anything in the array?
 
Upvote 0
Is there anything in the array?
Hi,yes it has data in the array, i have tried to modify as below, it's work for > & < condition but dont work for only Ary. Can you have a look please.

If Len(Join(Ary, "&")) > 200 Then
.Subject = "Multiple jobs"
ElseIf Len(Join(Ary, "&")) < 200 Then
.Subject = " " & Join(Ary, " & ")
ElseIf IsArray(Ary) Then
.Subject = Ary
End If
 
Upvote 0
You need to keep it in the order I showed, other it will fail if the array only has one value.
 
Upvote 0
You need to keep it in the order I showed, other it will fail if the array only has one value.

I keep it in order like below, but it return blank

With Sheets("Re-Open")
Ary = Application.Transpose(.Range("A5", .Range("A" & Rows.Count).End(xlUp)).Value)
End With

If IsArray(Ary) Then
txt = Ary

ElseIf Len(Join(Ary, "&")) > 200 Then
txt = "Multiple jobs"
Else
txt = Join(Ary, "&")
End If
.Subject = txt
 
Upvote 0
Oops, missed the Not
VBA Code:
   If Not IsArray(Ary) Then
      txt = Ary
   ElseIf Len(Join(Ary, "&")) > 200 Then
      txt = "Multiple jobs"
   Else
      txt = Join(Ary, "&")
   End If
   .Subject = txt
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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