concatenate multiple column till telephone value is found

shivam432

New Member
Joined
Mar 6, 2014
Messages
3
nameaddress1address2telephoneconcatenated column
abcsome address (alpha numeric)some address2 (alpha numeric)45678913some address some address 2 telephone

<tbody>
</tbody>
i have this problem i want to concatenate address 1 address 2 till the column with value telephone found

nameaddress1address2telephone
abcsome address (alpha numeric)some address2 (alpha numeric)45678913

<tbody>
</tbody>

result is above ,
hope i have cleared myself
need a macro that can solve my problem
thanks
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
.
.

Try something like this:

Code:
Private Function col_num(find_text As String, wrk_sht As Worksheet, Optional row_num As Long = 1) As Integer

    If row_num < 1 Or row_num > wrk_sht.Rows.Count Then Exit Function
    
    Dim top_row As Range
    Dim rng As Range
    
    With wrk_sht
        On Error Resume Next
        Set top_row = Intersect(.Rows(row_num).Cells, .UsedRange)
        On Error GoTo 0
    End With
    
    If top_row Is Nothing Then Exit Function
    
    find_text = LCase(Trim(find_text))
    
    For Each rng In top_row
        If LCase(Trim(rng.Value)) Like "*" & find_text & "*" Then
            col_num = rng.Column
            Exit Function
        End If
    Next rng

End Function

Sub Concatenate_Text()

    Dim col1 As Integer
    Dim col2 As Integer
    
    Dim lrow As Long
    Dim lcol As Integer
    
    Dim i As Long
    Dim j As Integer
    
    col1 = col_num("address1", ActiveSheet)
    col2 = col_num("telephone", ActiveSheet)
    
    With ActiveSheet
        lrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        lcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
    
    ActiveSheet.Cells(1, lcol + 1).Value = "Contact Details"
    
    For i = 2 To lrow
        For j = col1 To col2
            With ActiveSheet.Cells(i, lcol + 1)
                .Value = Trim(.Value & Space(1) & ActiveSheet.Cells(i, j).Value)
            End With
        Next j
    Next i

End Sub
 
Upvote 0
thanks for the reply but i am very new to macro , not able to understand the code,
this is how my excel looks , first two column are name and designation , third one contains address which is in distributed in many columns , so my manager wants when the compiler get the word telephone all column contains address till telephone get concatenate in one new column

1. WILLIAM G. BAIN Assistant General Counsel McKesson Corporation One Post Street 33rd Floor San Francisco California 94104-5296 Telephone: 415-983-8300909305251 United States Corporate Practice Profiles Section Copyright 2014 by Reed Elsevier Inc. LexisNexisContact DetailsContact DetailsContact DetailsContact DetailsContact DetailsContact Details
RESPONSIBILITIES: Intellectual Property; Corporate; Securities; Commercial Law
2. BERTRAM G. KAMINSKI Managing Counsel Oracle Corporation 500 Oracle Parkway (Redwood Shores) Redwood City California 94065 Telephone: 650-506-7000 Fax: 650-506-7114901221344 United States Corporate Practice Profiles Section Copyright 2014 by Reed Elsevier Inc. LexisNexis
RESPONSIBILITIES: Intellectual Property; Commercial Transactions; Contract Law

<colgroup><col span="6"><col><col><col><col><col><col><col><col><col span="5"></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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