- Show the Developer Tab in Excel
- Create a AddIn (xlam) workbook
- Open a new workbook
- Click on the Visual Basic button in the Developer Tab
- Right click in the Project pane and "Insert" > "Module"
- Paste the concatenate.vb contents in the new window
- Close the VisualBasic editor and save the workbook as a Excel Add-in (.xlam) Note that this file is global and should be present every time you open excel. If you delete it you will start getting a warning before you go to Tool>AddIns and remove it.
- Add the xlam file as addin in Tools > "Execel Add-ins"
- Add the macro to the Quick Access Toolbar
- Use it by clicking on the macro button and making a selection
Last active
January 21, 2020 10:44
-
-
Save angelyordanov/bbe117bf8466ac2045320d0620456798 to your computer and use it in GitHub Desktop.
Concatenate a range selection(number of rows) into the top rows' cells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Sub Concatenate() | |
Dim rSelected As Range | |
Dim col As Range | |
Dim c As Range | |
Dim first As Boolean | |
'Prompt user to select cells for formula | |
On Error Resume Next | |
Set rSelected = Application.InputBox(Prompt:= _ | |
"Select cells to create formula", _ | |
Title:="", Type:=8) | |
On Error GoTo 0 | |
Dim newLine As String | |
#If Win32 Or Win64 Then | |
newLine = Chr(10) | |
#ElseIf Mac Then | |
newLine = vbNewLine | |
#End If | |
'Only run if cells were selected and cancel button was not pressed | |
If Not rSelected Is Nothing Then | |
For Each col In rSelected.Columns | |
first = True | |
For Each c In col.Cells | |
If first = False Then | |
col.Cells(1).Value = col.Cells(1).Value & newLine & c.Value | |
c.Value = "" | |
End If | |
first = False | |
Next c | |
Next col | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment