Combine the string of two cells in one cell using BASIC

I have this program in VBA but step of combining the two cells in another didn’t work. How can i formulate it in Libreoffice basic. Thank you

Sub Concatenate_Example1()

Dim i As Integer

For i = 2 To 9
Cells(i, 3).Value = Cells(i, 1) & " " & Cells(i, 2)
Next i

End Sub

Your code actually joins the strings from 9 cells inserting spaces and places the result in the first one of these cells, doesn’t it? I’m not sure, however, whether the first index designates rows or columns in VBA.

No, the code goes through 8 rows (from 2 to 9), and in each row, it takes 1st and 2nd cells, concatenates them using a space, and puts the result to 3rd cell.

Sorry! @mikekaganski is right, of course, and I should have read more thorouly!
This also makes clear that a simple concatenation formula entered into C2 (Right? I never used VBA.) and filled down till C9 (?) should do the trick.

There is a simple function “CONCATENATE()” in LibreOffice.
Click into the result cell (eg B2). Click on the “Function Wizard”=“fx”.
Select the function “CONCATENATE()”. Enter the two cells containing the text (eg C2, D2). Click OK.

If my answer has solved your problem, please click on the checkmark ✓ in the circle image description to the left of the answer and click on the arrow ^ for upvote. This will tell the community that the question has been answered correctly.

Windows 10 Home; Version 1903; 64-Bit | LibreOffice, Version: 6.2.5.2 (x64).

Since V5.4.4 LibreOffice has the well working standard function TEXTJOIN() [ CONCAT() is also available, but unnecessary].
Assuming you want to apply the intended proceeding to A5:A13 (9 cells in a row) in the current sheet inserting one ordinary space between any two strings, you can use =TEXTJOIN(" "; 0; A5:A13) in an additional cell.
If you urgently want to place the result in A5 (for -most likely- bad reasons) you cannot do it by placing the formula there, of course. To do something by user code in such cases is a clearly bad idea. If you insist on it anyway, however, don’t try it by adapting VBA code, but learn a bit about LibreOffice BASIC and the API (uno-API) and design your code based on these proper means from scratch.

===Edit 2019-08-02 13:41UTC===
The comment by @mikekaganski critisising my first comment on the question is right and makes clear that even TEXTJOIN() doesn’t bring advantages over a simple concatenatiion like = A2 & " " & B2 entered into C2 and filled down as far as needed in this case.

===Edit 2019-08-05 14:55 UTC===
The example announced in my recent comment.

1 Like

BTW: Excel 2016 or so is told to also have a TEXTJOIN().

Lupp and Mike,thank you very much for your answers, . I have to use LO Basic because i want integrate this procedure small procedure in another macro.

Then I would suppose you need it less specialised. I cannot easily imagine many use-cases where exactly the range A2:B9 needs to be treated that way.
And once again: Don’t try to move/translate Excel-VBA but develop your code basically for LibO usung the API. I will attach an example .ods containing a bit of related code.