Macro/VBA question

dracer

Board Regular
Joined
Jul 30, 2014
Messages
76
Office Version
  1. 365
  2. 2019
Hi there. I'm trying to combine a bunch of cells in the same row into one formula with a pipe | in between the numbers. eg A1&"|"&A2&"|"&A3 etc. Can this be automated so this can be done automatically from the first row in a column with a value until the last row in a column with data. Like A1 to A83. I've been doing this manually. Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
bunch of cells in the same column you mean?

Use a macro...

Code:
Sub CombineCells()
    Dim result As String
    Dim row As Long, endRow As Long
    endRow = Cells(Rows.Count, 1).End(xlUp).Row
    For row = 1 To endRow
        result = result & Cells(row, 1).Value
        If Not row = endRow Then
            result = result & " | "
        End If
    Next row

    Range("B1").Value = result
End Sub
 
Last edited:
Upvote 0
Thanks!!! This is incredible. Saves me a lot of work down the line. One more question. Is there a place where I can save my various codes so I can access them. They are usually attached to the workbooks, but I'm wondering if I can see many marcos at once.
 
Upvote 0
No problem... and yeah, this is what the Personal workbook is for. This workbook is programmed to open with excel but it is hidden in the background. On this workbook you should save all your macros that you use frequently. If you go into the vba editor you will see it in the project list. You can additionaly setup hot keys for these macros in the workbook to call by key press or even better you can make buttons on your ribbon to call them.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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