CONCATENATE

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have the code and is all perfect on if the data is in col e and f, bus as per the table the data will start for E and end to AA, so ned to modify the code to get the right output

Book2
BCDEFGHIJ
1Actual Bundle EtherOutPut
2BE10Gi101/0/0/4 ; Gi102/0/0/4 Gi101/0/0/4 Local Configured 0x8000 Gi102/0/0/4 Local Active 0x8000
3BE40Gi101/0/0/13 Gi101/0/0/13 Local Active 0x8000
4BE50Te0/2/0/3 ; Te0/3/0/3 Te0/2/0/3 Local Active 0x8000 Te0/3/0/3 Local Active 0x8000
5BE101Te0/3/0/9 Te0/3/0/9 Local Active 0x8000
6BE110Gi100/0/0/25 ; Gi101/0/0/25 Gi100/0/0/25 Local Active 0x8000 Gi101/0/0/25 Local Active 0x8000
7BE120Gi100/0/0/24 ; Gi101/0/0/24 Gi100/0/0/24 Local Active 0x8000 Gi101/0/0/24 Local Active 0x8000
8BE130Gi100/0/0/27 Gi100/0/0/27 Local Active 0x8000
9BE1000Te0/2/0/18 ; Te0/2/0/19 ; Te0/3/0/18 ; Te0/3/0/19 Te0/2/0/18 Local Active 0x8000 Te0/2/0/19 Local Active 0x8000 Te0/3/0/18 Local Active 0x8000 Te0/3/0/19 Local Active 0x8000
10BE10Te0/0/0/6 ; Te0/1/0/6 Te0/0/0/6 Local Active 0x8000 Te0/1/0/6 Local Active 0x8000
11BE20Te0/0/0/5 ; Te0/1/0/5 Te0/0/0/5 Local Active 0x8000 Te0/1/0/5 Local Standby 0x8000
12BE40Te0/0/0/12 ; Te0/0/1/4 ; Te0/1/0/12 ; Te0/1/1/4 Te0/0/0/12 Local Active 0x8000 Te0/0/1/4 Local Active 0x8000 Te0/1/0/12 Local Active 0x8000 Te0/1/1/4 Local Active 0x8000
13BE500Te0/0/0/11 ; Te0/1/0/11 ; Te0/2/0/3 ; Te0/2/0/11 ; Te0/3/0/3 ; Te0/3/0/11 Te0/0/0/11 Local Active 0x8000 Te0/1/0/11 Local Active 0x8000 Te0/2/0/3 Local Active 0x8000 Te0/2/0/11 Local Active 0x8000 Te0/3/0/3 Local Active 0x8000 Te0/3/0/11 Local Active 0x8000
Sheet1




It works only for E and F columns, need to en till the last non blank cells in column B
VBA Code:
Sub ExtractAndCombineperfect()


    ' Get values from E2 and F2
    Dim valueE As String
    Dim valueF As String

    valueE = Range("E2").Value
    valueF = Range("F2").Value

    ' Take the first 14 characters from each value
    Dim truncatedValueE As String
    Dim truncatedValueF As String

    truncatedValueE = Left(valueE, 14)
    truncatedValueF = Left(valueF, 14)

    ' Combine truncated values with a semicolon and put the result in G2
    Range("D2").Value = Application.WorksheetFunction.Trim(truncatedValueE & ";" & truncatedValueF)
End Sub
 
Thanks for pointing out (it looks like it to the eye, but I can't find a space in my cut and pasted data)

Anyway, I'll let the OP comment and see if what we have here is fitting their needs before proceeding further..

cheers
Rob
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Did you use the copy icon just above the row numbers?
 
Upvote 0
Sub test() For Row_num = 2 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row ' find the last row of data in Col B For Col_no = 5 To 27 '(count from Col E to Col AA) If Cells(Row_num, Col_no) = "" Then Exit For 'go to next row if col is empty (to save time) mydata = mydata & Left(Cells(Row_num, Col_no), InStr(Cells(Row_num, Col_no), " ")) & " ; " Next Col_no Range("D" & Row_num).Value = mydata mydata = "" 'reset mydata to blank for next row Next Row_num End Sub
I have run this code but not giving correct output, in coumn D

1701962919447.png
 
Upvote 0
@Fluff ... LOVE that button .:-) I've never noticed it before .. every day a school day ..

Try this version then :

VBA Code:
Sub test()

For Row_num = 2 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row ' find the last row of data in Col B

    For Col_no = 5 To 27  '(count from Col E to Col AA)
        
        If Cells(Row_num, Col_no) = "" Then Exit For  'go to next row if col is empty (to save time)
            tempdata = Right(Cells(Row_num, Col_no), Len(Cells(Row_num, Col_no)) - 2)
            mydata = mydata & Left(tempdata, InStr(tempdata, " ")) & "; "
    
    Next Col_no
    
    Range("D" & Row_num).Value = Left(mydata, Len(mydata) - 3)
    tempdata = "" 'reset temp & mydata to blank for next row
    mydata = ""
    
Next Row_num

End Sub
 
Upvote 0
Solution
Sub test() For Row_num = 2 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row ' find the last row of data in Col B For Col_no = 5 To 27 '(count from Col E to Col AA) If Cells(Row_num, Col_no) = "" Then Exit For 'go to next row if col is empty (to save time) tempdata = Right(Cells(Row_num, Col_no), Len(Cells(Row_num, Col_no)) - 2) mydata = mydata & Left(tempdata, InStr(tempdata, " ")) & "; " Next Col_no Range("D" & Row_num).Value = Left(mydata, Len(mydata) - 3) tempdata = "" 'reset temp & mydata to blank for next row mydata = "" Next Row_num End Sub
@RobP

Thnak you for quick response, but it have stop here (ref screen shot) and error on line

VBA Code:
Range("D" & Row_num).Value = Left(mydata, Len(mydata) - 3)  'Run Time Error 5

so moditied a bit, hope i did the right think, rest the output is correct, pleae advice

VBA Code:
[B]On Error Resume Next[/B]
    Range("D" & Row_num).Value = Left(mydata, Len(mydata) - 3)


1701963360204.png
 
Upvote 0
thanks for feedback - indeed hard to know why its stopped, as we cannot see your actual data there from each cell. The caveat here in my code is that it assumes there is always 2 " " spaces before your data, hence starts to look from char 3. Maybe that data is slightly different there in that row ? (ah, I see you have blank rows in your data .. and I have no error trapping..)_

anyway, if you have made it work for you - then thats good ..

cheers
Rob
 
Upvote 0

Fluff

replace to dictionary..
VBA Code:
Sub ExtractAndCombineperfect()
    Set abc = CreateObject("Scripting.Dictionary")
    For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
        For j = 5 To Cells(i, Columns.Count).End(xlToLeft).Column
            dict.Add CStr(Split(Cells(i, j))(0)), j
        Next
     Cells(i, 4).Value = Join(abc.keys, ";")
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,758
Members
452,996
Latest member
nelsonsix66

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