Help to write a macro for calc

I have very often in Calc sheets many cells looking like

image description

I need to add a line break before the “[” and use a bold format for all between and including “[”. “]” so that the cell looks like:

image description

Using the record macro function does not work in this case (which I can understand) and I don’t have enough macro programming knowledge to write a macro myself from the scratch.

Any help to write this macro is highly appreciated.

LibO version:

This macro finds the opening bracket in text for a selection of cells, inserts a line feed and emboldens the balance of the line. I had to resize the cell vertically to see both resulting lines.

Sub BoldPart
rem and
   Dim oDoc As Object
   Dim oSelection As Object
   Dim oCell As Object
   Dim oCursor As Object
   Dim oText As Object
   Dim colonLoc As Long
   Dim i As Long
   oDoc = ThisComponent
   oSelection = oDoc.CurrentController.Selection
   for i = 0 to oSelection.Rows.Count - 1
      oCell = oSelection.getCellByPosition(0,i)
      oText = oCell.getText()
      bracketLoc = InStr(oText.String,"[")
      if bracketLoc > 0 then
         oCursor = oText.createTextCursor
         oCursor.CharWeight =
   next i
End Sub

Thank your very much for this macro. I got it running and it works just fine!