VBA: How to combine string from two different cells into one?

mtbthepro

Board Regular
Joined
Feb 22, 2017
Messages
91
Hi there,
I would like to know if there is a way to combine two strings together into one cell. I am talking about putting numbers together, there is a set of Account#which are on different lines and they are displayed like |Account#:12542-|5651256|" The pipe (|) is there to show the column line that runs in between them. I would like that line to disappear and the number after the "-" to be in the same cell as "Account#: " so end result should look something like "|Account#:12542-5651256|"
I know there is a way to do it which is called concatenate and I have tried it a couple of different ways but it doesn't work.

If you can help me with this I would greatly appreciate it.




example one
Code:
      For N = nlast To 1 Step -1
                        If ws.Cells(N, 1).Value Like "*ACCOUNT*" Then
                            ws.Cells(N, 1).Value = str1
                            ws.Rows(N).EntireRow.Font.Bold = True
                            ws.Rows(N).Offset(0, 1) = str2
                            ws.Rows(N) = CONCATENATE(str1 & str2)  
                        End If
                    Next N
example two
Code:
        st= .Cells(.Rows.Count, "A")
                    For i = i To 1 Step -1
                If (ws.Cells(i, 1).Value Like "*ACCOUNT*") Then
                    st1= RTrim(.Cells(i, "A") & .Cells(i, "B"))
                        End If
                    Next i
 
This is the answer which works for me... It applies to all my sheet and formats

Code:
    For r = 1 To ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
                        If ws.Cells(r, "A") Like "*ACCOUNT*" Then
                            ws.Cells(r, "A").Value = ws.Cells(r, "A").Text & ws.Cells(r, "B").Text
                            ws.Cells(r, "B").ClearContents
                            ws.Rows(r).Font.Bold = True
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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