range of cells concatenated to one field?

cccbzg

Board Regular
Joined
Oct 5, 2014
Messages
61
Hello,

I would like to write the value of a range I've selected to a particular cell. In other words, I want to write the value of the entire range to a cell. So for example, the range may include col A rows 3,4, and 5. Can this concatenated range be treated as one value to be output to a cell?
Can't seem to get that to work. Tried Valrange1 = Range("A" & s5row & ":A" & drow).Value, and then Cells(arow, 48) = Valrange1, but that only got me the first value in the range. Thought perhaps I needed DIM Valrange1 AS Range, but that caused an error.



Here's how I set up the range:



With Sheets("INPUT").Range("A" & s5row & ":A" & drow)

Set DXrng = .Find(What:=DDXit, _

After:=.Cells(.Cells.Count), _

LookIn:=xlValues, _

LookAt:=xlPart, _

SearchOrder:=xlByRows, _

SearchDirection:=xlNext, _

MatchCase:=False)

End With



Help much appreciated.
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

dcardno

Well-known Member
Joined
Nov 20, 2002
Messages
534
Office Version
  1. 2013
Platform
  1. Windows
I use a User-Defined Formula for this, as Excel doesn't have a native operator:
Code:
Function ConcatAll(rgVals as Range, stSep as String) as String

Dim cl as Range

For Each cl in rgVals
   If cl.Value <> "" Then
      ConcatAll = ConcatAll & cl.Value & stSep
   End If
Next cl

ConcatAll = Left(ConcatAll, Len(ConcatAll) - Len(stSep))

End Function

The stSep just allows me to control what is used as a separator - semi-colons for names on e-mail, commas or spaces for other purposes, etc.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,914
Members
413,952
Latest member
JGer

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
Top