Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ConcatRange

Status
Not open for further replies.

iod1982

Programmer
Mar 1, 2006
2
US
Hey everyone,

I am trying to write a VBA function that will allow me to pass it a single range argument and that returns the concatenation of all the cells in the range.

Please help
 
If "r" is your range, how about

total = ""
for each c in r.cells
total = total & c.value
next


_________________
Bob Rashkin
 
Very similar to Bong's solution, here is a complete function:
Code:
Function ConcatCells(ByVal oRange As Range) As String
Dim oCell As Range
Dim sResult As String

   sResult = ""
   For Each oCell In oRange
     sResult = sResult & oCell.Text
   Next oCell
   ConcatCells = sResult
   
End Function


Regards,
Mike
 


Hi,

The RANGE is already a concatenation of all the cells in the range.

However, if you want the concatenation of all the VALUES in the range...
Code:
Function ConcatValues(rng as range) as string
   Dim r as range
   for each r in rng
      ConcatValues = ConcatValues & r.value
   next
End Function


Skip,

[glasses] [red]Be Advised![/red] A man's home is his castle...
in a Manor of speaking. [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top