Concatenate a named range with text to one cell using in VBA?

perola.rike

Board Regular
Joined
Nov 10, 2011
Messages
151
I need a little code that merges a range of cells (A26:A100) named "NPresults" that contains text only, into the cell A26. I need . as delimiter, not comma.
I need this in VBA because it is part of a larger code.

Any ideas how to solve this?

For some hours now, I have looked but not found any solution, searching on concatenate formulas etc.

Best regards, Per-Ola Rike
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi

The following should work:

Code:
Dim vArr As Variant
Dim itm As Variant
Dim temp As String

vArr = Range("NPresults").Value

For Each itm in vArr
  temp = temp & "." & itm
Next itm

Range("B1")).Value = Mid(temp,2)

Obviously change destination to suit
 
Upvote 0
Thanks for reply. I did not seem to work, I got a rumtime error 13, type mismatch. Seems like it's the "temp = temp& "." & itm" that wouldnt work...

Hi

The following should work:

Code:
Dim vArr As Variant
Dim itm As Variant
Dim temp As String

vArr = Range("NPresults").Value

For Each itm in vArr
  temp = temp & "." & itm
Next itm

Range("B1")).Value = Mid(temp,2)

Obviously change destination to suit
 
Upvote 0
Do you have error values in your named range?

Try changing that line to:

Code:
temp = temp & "." & CStr(itm)
 
Upvote 0
In some way I managed to figure it out, so your code worked. I just had to tweak the other parts of my own code to fit in with yours.
Thank you!



Do you have error values in your named range?

Try changing that line to:

Code:
temp = temp & "." & CStr(itm)
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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