Hi!
I had a problem and Fluff and Mumps solved it both professionally. I am practising now, so I try to modify their codes, but there is something wrong.
I want to keep the part of their codes, which splits the cell's content after every space, but at the command part, what i highlighted with RED, I want to add a new command.
It would make every word BOLD in column "B", which starts with the Left(Word,2) in column "A"
I made a picture so it's easier to understand:
https://imgur.com/a/xo3ro5G
First topic:
https://www.mrexcel.com/forum/excel...-cell-make-decision-depending-its-length.html
Fluff's solution:
Code:
Sub trimWords()
Dim Wrd As Variant
Dim Cl As Range
Range("A:A").Replace Chr(10), " ", , , , , False, False
For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
For Each Wrd In Split(Cl, " ")
Cl.Offset(, 1).Value = Cl.Offset(, 1).Value & " " & IIf(Len(Wrd) <= 6, Left(Wrd, 1), Left(Wrd, 2))
Next Wrd
Next Cl
End Sub
Mumps solution:
Code:
Sub makiwara()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim rng As Range
Dim vRng As Variant
Dim i As Long
For Each rng In Range("A1:A" & LastRow)
vRng = Split(rng, " ")
For i = LBound(vRng) To UBound(vRng)
If Len(vRng(i)) <= 6 Then
rng.Offset(0, 1) = Trim(rng.Offset(0, 1) & " " & Left(vRng(i), 1))
Else
rng.Offset(0, 1) = Trim(rng.Offset(0, 1) & " " & Left(vRng(i), 2))
End If
Next i
Next rng
Application.ScreenUpdating = True
End Sub
And the 2. part of the code which I want to add instead of the RED lines:
Sub MakeSomeWordsBold()
Dim R As Long, x As Long, TwoLetters As String, CellText As String
With Sheets("animals")
For R = 1 To .Cells(Rows.Count, "A").End(xlUp).Row
Do
TwoLetters = Left(.Cells(R, "A").Value, 2)
CellText = .Cells(R, "B").Value
x = InStr(x + 1, CellText, TwoLetters, vbTextCompare)
If x Then .Cells(R, "B").Characters(x, InStr(x, .Cells(R, "B").Value, " ") - x + 1).Font.Bold = True
Loop While x
Next
End With
End Sub
Can somebody help me, how to combine Fluff's or Mumps' solution with the "bold making" part?
I really appreciate your patience and help, I hope one day I will have the knowledge of you, to give back to the Forum Members! Have a nice day!
I had a problem and Fluff and Mumps solved it both professionally. I am practising now, so I try to modify their codes, but there is something wrong.
I want to keep the part of their codes, which splits the cell's content after every space, but at the command part, what i highlighted with RED, I want to add a new command.
It would make every word BOLD in column "B", which starts with the Left(Word,2) in column "A"
I made a picture so it's easier to understand:
https://imgur.com/a/xo3ro5G
First topic:
https://www.mrexcel.com/forum/excel...-cell-make-decision-depending-its-length.html
Fluff's solution:
Code:
Sub trimWords()
Dim Wrd As Variant
Dim Cl As Range
Range("A:A").Replace Chr(10), " ", , , , , False, False
For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
For Each Wrd In Split(Cl, " ")
Cl.Offset(, 1).Value = Cl.Offset(, 1).Value & " " & IIf(Len(Wrd) <= 6, Left(Wrd, 1), Left(Wrd, 2))
Next Wrd
Next Cl
End Sub
Mumps solution:
Code:
Sub makiwara()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim rng As Range
Dim vRng As Variant
Dim i As Long
For Each rng In Range("A1:A" & LastRow)
vRng = Split(rng, " ")
For i = LBound(vRng) To UBound(vRng)
If Len(vRng(i)) <= 6 Then
rng.Offset(0, 1) = Trim(rng.Offset(0, 1) & " " & Left(vRng(i), 1))
Else
rng.Offset(0, 1) = Trim(rng.Offset(0, 1) & " " & Left(vRng(i), 2))
End If
Next i
Next rng
Application.ScreenUpdating = True
End Sub
And the 2. part of the code which I want to add instead of the RED lines:
Sub MakeSomeWordsBold()
Dim R As Long, x As Long, TwoLetters As String, CellText As String
With Sheets("animals")
For R = 1 To .Cells(Rows.Count, "A").End(xlUp).Row
Do
TwoLetters = Left(.Cells(R, "A").Value, 2)
CellText = .Cells(R, "B").Value
x = InStr(x + 1, CellText, TwoLetters, vbTextCompare)
If x Then .Cells(R, "B").Characters(x, InStr(x, .Cells(R, "B").Value, " ") - x + 1).Font.Bold = True
Loop While x
Next
End With
End Sub
Can somebody help me, how to combine Fluff's or Mumps' solution with the "bold making" part?
I really appreciate your patience and help, I hope one day I will have the knowledge of you, to give back to the Forum Members! Have a nice day!
Last edited: