lock cells<\/a>, so you won\u2019t delete it by accident. It\u2019s\nstill not the best option.<\/p>\n\n\n\nWhere Excel is not enough, VBA will take care of it. That\u2019s\nwhy we are going to create a function that will help us to deal with the\nproblem.<\/p>\n\n\n\n
First, open the VBA code editor (Left Alt + F11<\/strong>) and create a new module.<\/p>\n\n\n\n <\/figure>\n\n\n\nInside this module insert the following code.<\/p>\n\n\n\n
Function CONCATSEP(ParamArray var() As Variant) As String\n Dim i As Integer\n Dim result As String\n Dim separator As String\n \n separator = var(UBound(var))\n \n If UBound(var) > 1 Then\n For i = LBound(var) To UBound(var) - 1\n If i > 0 Then\n result = result + separator + var(i)\n Else\n result = result + var(i)\n End If\n Next\n End If\n CONCATSEP = result\nEnd Function<\/code><\/pre>\n\n\n\nCode explanation:<\/strong><\/p>\n\n\n\nWe use ParamArray\nvar() As Variant<\/strong> because we don\u2019t know how many arguments will be inside\nthe function. This allows us to take any number.<\/p>\n\n\n\nseparator = var(UBound(var))<\/strong> – This part of the code get values from the last element and assigns it to the separator<\/strong> variable.<\/p>\n\n\n\nIf UBound(var) > 1\nThen<\/strong> – If there are at least three arguments (two strings + separator) use\nthe code inside. Counting starts from 0 and then 1, 2. That\u2019s why we are\ntalking about three arguments and not two.<\/p>\n\n\n\nInside the If<\/strong> function, the program checks whether we are dealing with the first argument. We don\u2019t want to add a separator at the beginning of the first argument, because it will return a string with the separator at the beginning.<\/p>\n","protected":false},"excerpt":{"rendered":"When you work with Excel, you probably have to deal with data separated into multiple rows. For example name, city, age, etc. But…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[170,190],"yoast_head":"\n
Combine Cells in Excel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n