And the answer will be in a form of our desire. Since we have made it Sign parameter optional, we can use write the formula without it. And it combined the cells having comma as the separator. Here we have provided the range and the delimiter sign within the function.
Opposite of merging cells in excel code#
Notice that before inserting a value in the result, we have checked whether it’s empty or not.Ĭombine = Left(ResultStr, Len(ResultStr) - Len(Sign)) line of code to eradicate the delimiter for the last cell. Then we used a loop to iterate through the cells within our range and forms the result in the ResultStr variable. Within the function, we have declared a couple of variables Rng as Range and ResultStr as String. Which takes two parameters at most (Sign is an optional one). Here we have created a function, Combine. Now insert the following code in the code window Function Combine(WorkRng As Range, Optional Sign As String = ", ") As StringĬombine = Left(ResultStr, Len(ResultStr) - Len(Sign)) Then right-click on the project name and click Module from Insert. Open the Microsoft Visual Basic for Application window, the shortcut key is ALT + F11. Sensing VBA Code!!! Yes, in this section, we will write VBA code to build a function to combine multiple cells into one. You can create your own function to combine cells. User-Defined Function to Combine Cells (VBA Code) This is the formula and we hope that you remember the steps to get the desired result. If we use the CONCATENATE function, then the formula will be like the following one We can combine the rows using the CONCATENATE or CONCAT function. Combine Using the CONCATENATE/CONCAT Function You will know the procedure from this merging rows article. You can see, we have merged the rows here. Will combine the rows that contain the name of the books for a particular author. Now the books are in a single column (but in different rows). Previously we have seen the ways of combining cells from columns, in this section, we will see the approaches for combining cells over the rows.įor example, we have rearranged our authors-books dataset. You can use your preferred character, so do the functions or features. All you need to do is provide the character like we provided commas.įor example, here, we have used the hyphen sign (-) as the delimiter. Note that, here we are showing comma as the separator, you can use any character as the delimiter. Keep one thing in mind, Flash Fill may sometimes fail to work if you only have the sample cell selected, in such cases, you will need to select the other cells (stores rests of the results) as well. You will find the combination of cells in the result. Then selecting the cell click the Flash Fill option from the Data Tools section from the Data tab (you can use the keyboard shortcut CTRL + E as well). So, let’s write the names for the first one.
Here, we want to combine the books’ names separated by a comma. To use the feature, first of all, you need to write the cell values into a cell in a form you want to combine. Let’s write the formula for the rest of the cells.Įxcel Flash Fill feature can be a handy tool to combine cells. So, if there is an empty cell within the provided cells or range of cells, it will discard that and combine only the cells that have values. One thing to note, in our formula we have enabled Ignore empty cells. And as our delimiter is a comma, values as separated by the comma. This has also combined multiple cells into one cell.