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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi & welcome to MrExcel.
How about
VBA Code:
Sub bumbum()
   Dim Ary As Variant
   With Sheets("Sheet1")
      Ary = Application.Transpose(.Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value)
   End With
   MsgBox Join(Ary, "&")
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub bumbum()
   Dim Ary As Variant
   With Sheets("Sheet1")
      Ary = Application.Transpose(.Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value)
   End With
   MsgBox Join(Ary, "&")
End Sub

Thank you so much for your fast & simple solution. God bless you ?
 
Upvote 0
How about
VBA Code:
Sub bumbum()
   Dim Ary As Variant
   With Sheets("Sheet1")
      Ary = Application.Transpose(.Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value)
   End With
   If IsArray(Ary) Then MsgBox Join(Ary, "&") Else MsgBox Ary
End Sub
 
Upvote 0
How about
VBA Code:
Sub bumbum()
   Dim Ary As Variant
   With Sheets("Sheet1")
      Ary = Application.Transpose(.Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value)
   End With
   If IsArray(Ary) Then MsgBox Join(Ary, "&") Else MsgBox Ary
End Sub

How can i implement the Ary to

.Subject in outlook email, i need to take the Ary with "&" if my data is from A1:A2 and take only Ary if my data is from A1

My previous code was

.Subject = "Hello" & "-" & Join(Ary, " & ")

Thank you so much
 
Upvote 0
Just replace the msgbox with the subject line.
 
Upvote 0
Use
VBA Code:
If IsArray(Ary) Then .Subject ="Hello -"& Join(Ary, "&") Else .Subject= "Hello -" & Ary
 
Upvote 0

Forum statistics

Threads
1,212,931
Messages
6,110,745
Members
448,295
Latest member
Uzair Tahir Khan

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