Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Populate the Concatenate function using VBA

Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate the Concatenate function using VBA

For i = 1 To 70
myValue = myValue & Cells(Activecell.Row,i)
Next i

'then do something with myValue

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Michael Beckinsale" wrote in message
...
Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Populate the Concatenate function using VBA

Option Explicit
Function ConcatenateRange(rSource As Range) As String
Dim rCell As Range
For Each rCell In rSource
ConcatenateRange = ConcatenateRange & rCell.Text
Next
End Function

Then in the worksheet you can type e.g. =ConcatenateRange(A1:BR1)

hth
Andrew Taylor

Michael Beckinsale wrote:
Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Populate the Concatenate function using VBA

Bob & Andrew,

Many thanks for your prompt replies, both of which do the job as described
very well.

As the concatenation of 70 columns needs to be applied to anything between
100 and 5000 rows l am inclined to use Andrews solution rather than using
Bob's and looping thru the rows.

Can either of you see a problem in that?

Again many thanks

Michael
"Michael Beckinsale" wrote in message
...
Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate the Concatenate function using VBA

I would go one stage further, do it all in one batch macro.

This works from row 1 to the last row and concatenates values from column 2
out, and drop the result in column A. Change to suit

Sub ConcatenateRange()
Dim val As String
Dim iLastRow As Long
Dim iLastCol As Long
Dim i As Long
Dim j As Long
iLastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For i = 1 To iLastRow
iLastCol = Cells(i, Columns.Count).End(xlToLeft).Column
val = ""
For j = 2 To iLastCol
val = val & Cells(i, j)
Next j
Cells(i, "A").Value = val
Next i
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Michael Beckinsale" wrote in message
...
Bob & Andrew,

Many thanks for your prompt replies, both of which do the job as described
very well.

As the concatenation of 70 columns needs to be applied to anything

between
100 and 5000 rows l am inclined to use Andrews solution rather than using
Bob's and looping thru the rows.

Can either of you see a problem in that?

Again many thanks

Michael
"Michael Beckinsale" wrote in message
...
Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if

the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Populate the Concatenate function using VBA

Bob,

That looks great. Will try it out over the weekend as l have to go out now
and will let you know how l got on.

Again many thanks to both of you.

Michael
"Bob Phillips" wrote in message
...
I would go one stage further, do it all in one batch macro.

This works from row 1 to the last row and concatenates values from column
2
out, and drop the result in column A. Change to suit

Sub ConcatenateRange()
Dim val As String
Dim iLastRow As Long
Dim iLastCol As Long
Dim i As Long
Dim j As Long
iLastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For i = 1 To iLastRow
iLastCol = Cells(i, Columns.Count).End(xlToLeft).Column
val = ""
For j = 2 To iLastCol
val = val & Cells(i, j)
Next j
Cells(i, "A").Value = val
Next i
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Michael Beckinsale" wrote in message
...
Bob & Andrew,

Many thanks for your prompt replies, both of which do the job as
described
very well.

As the concatenation of 70 columns needs to be applied to anything

between
100 and 5000 rows l am inclined to use Andrews solution rather than using
Bob's and looping thru the rows.

Can either of you see a problem in that?

Again many thanks

Michael
"Michael Beckinsale" wrote in message
...
Hi All,

Bit of a strange one this!

I need to concatenate several columns (actually 70) and wondered if

the
Concatenate Function could be populated using VBA.

Does anybody have the code to do this or able to point me in the right
direction please ?

I realise that the function is limited to 30 columns but l could do the
concatenate 3 times then concatenate them.

TIA

Michael Beckinsale







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function to populate cells?? BAS Excel Worksheet Functions 3 January 30th 08 06:56 PM
How to accept input and then populate/concatenate this with other Pank New Users to Excel 4 February 27th 07 03:38 PM
function to populate different cell Mike Excel Worksheet Functions 0 April 17th 06 05:55 AM
Function for Auto Populate [email protected] Excel Worksheet Functions 3 July 28th 05 03:26 AM
populate concatenate field igor Excel Programming 2 August 13th 03 08:39 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"