Moving specific cell data

I don’t know any code. I created the following code using AI. The code works but it doesn’t work the way I want it to work.
What the code does: Understand the data with color code #000000 inside the cell I selected and move the data starting with this # as TEXT to the cells right next to the cell I selected in order.
Example; If the cell I selected is F3:I3, I want to move the data starting with # in it not to cells F3, G3, H3 and I3 but to the next cell J3 and if there is more than one # code, next to J3 and if there is more than one # code, next to it.
The code below works but what it does is, using the cell numbers above as an example, it defines the starting point as G3 instead of J3 and moves the #000000 codes to this G3 cell as the starting point.

Below is an example of cell construction.

image

Sub TasiRenkKodu
Dim oSheet As Object
Dim oCell As Object
Dim sText As String
Dim sNewText As String
Dim sColorCodes As String
Dim sColorCode As String
Dim i As Integer
Dim j As Integer
Dim oCellAddress As New com.sun.star.table.CellAddress
Dim oMergedRange As Object
Dim nStartColumn As Integer
Dim nEndColumn As Integer
Dim nNextColumn As Integer

oSheet = ThisComponent.CurrentController.ActiveSheet
oCell = ThisComponent.CurrentController.getSelection()

If IsNull(oCell) Then
MsgBox "Lütfen bir hücre seçin."
Exit Sub
End If

' Seçilen hücrenin gerçek adresini bul'
oCellAddress = oCell.getCellAddress()

' Birleştirilmiş hücre aralığını bul'
oMergedRange = oSheet.getCellRangeByPosition(oCellAddress.Column, oCellAddress.Row, oCellAddress.Column, oCellAddress.Row)
nStartColumn = oCellAddress.Column
nEndColumn = nStartColumn + oMergedRange.Columns.getCount() - 1

sText = oCell.getString()
sNewText = ""
sColorCodes = ""

i = 1
While i <= Len(sText)
If Mid(sText, i, 1) = "#" Then
j = i
While j <= Len(sText) And Mid(sText, j, 1) <> " "
j = j + 1
Wend
sColorCode = Mid(sText, i, j - i)
sColorCodes = sColorCodes & sColorCode & vbNewLine
i = j
Else
sNewText = sNewText & Mid(sText, i, 1)
i = i + 1
End If
Wend

oCell.setString(Trim(sNewText))

' Renk kodlarını doğru hücreye taşı'
nNextColumn = nEndColumn + 1
Dim oNextCell As Object
oNextCell = oSheet.getCellByPosition(nNextColumn, oCellAddress.Row)
oNextCell.setString(Trim(sColorCodes))

MsgBox "Renk kodları başarıyla taşındı."
End Sub

easier : Importing and Exporting Data in Text Format

1 Like

Or, if already imported then Data > Text to Columns for same dialogue. Note Setting irrelevant data to Hide (not import).

1 Like

The TEXT text was a sample text that I modified when I imported it here. In place of that text there are different texts between 1 and 3 words.

Example;
Text Text Text Text : #00000 #11111
Text Text : #F1F1F1F1 #F0000 # 98B1CE

:smile:

still, the separator is :

1 Like

I wrote one extra, are you laughing at that? :joy:

I tried the method you mentioned doesn’t work as I want. If there is more than one text before :, they are all assigned to separate cells. I want every color code starting with # to be in a separate cell, including this character.

Anyway, I already solved it in another way. No need for help.

User-defined Number Formats