VBA to concatenate variables in a formula and separate by a space

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

How do I get a space to appear between the two concatenated values?


Code:
LineText = "=" & CustNameReference & InvoiceReference


The two variables are cell addresses:
CustNameReference = $A$1 = John Smith
InvoiceReference = $B$1 = 123

When I execute the code
Code:
Range("C1") = LineText

I want the formula in C1 to appear like =$A$1&" "&$B$1
so the result is John Smith 123.

As it is now, the result is John Smith123 (no space between the name and invoice).

Thanks,

GL
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Like this?

Code:
LineText = "=" & CustNameReference & " " & InvoiceReference
 
Upvote 0
VoG,

Thanks for pointing me in the right direction. I was thinking I needed to use Chr(160) to get a space.

I played with your proposed code and ended up with:

Code:
LineText = "=" & CustNameReference & "& "" "" &" & InvoiceReference

I won't try to understand how many &'s and pairs of quotes were used. Knowing it works is all I need for now.

GL
 
Upvote 0

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

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