Thank you so much! Can you give me the code for highlight all of the words from a wordlist within cells. I mean, i want to colour many different words at the same time
Sub HighlightLängdInColumnQ() ' This macro highlights occurrences of the word "längd" (case-insensitive) in each cell in column Q. ' Disable screen updating to improve performance Application.ScreenUpdating = False ' Declare variables Dim targetCell As Range ' The cell in column Q where "längd" will be searched and highlighted Dim searchText As String ' The text string to be highlighted Dim tempString As String ' Temporary string to keep track of the processed text Dim startIdx As Long ' Starting index for highlighting Dim occurrenceCount As Long ' Number of occurrences found in each cell ' Set the text string to "längd" searchText = "längd" ' Calculate the length of the search text Dim searchTextLength As Long searchTextLength = Len(searchText) ' Loop through each cell in column Q within the selected range For Each targetCell In Range("Q:Q").Cells If Not IsEmpty(targetCell) Then With targetCell ' Convert cell content and search text to lowercase for case-insensitive comparison Dim cellContent As String cellContent = LCase(targetCell.Value) Dim searchLower As String searchLower = LCase(searchText) ' Find the number of occurrences of "längd" (case-insensitive) in the cell occurrenceCount = UBound(Split(cellContent, searchLower)) ' Check if there is at least one occurrence If occurrenceCount > 0 Then ' Initialize the temporary string tempString = "" ' Loop through each occurrence For startIdx = 0 To occurrenceCount - 1 ' Concatenate the text before the occurrence to the temporary string tempString = tempString & Split(cellContent, searchLower)(startIdx) ' Highlight the current occurrence of "längd" (preserving original case) .Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Font.ColorIndex = 3 ' Red color ' Concatenate the search text to the temporary string tempString = tempString & Mid(targetCell.Value, Len(tempString) + 1, searchTextLength) Next startIdx End If End With End If Next targetCell ' Re-enable screen updating Application.ScreenUpdating = True End Sub
Change the following line from the code: .Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Font.ColorIndex = 5 To This: .Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Delete
Hi its great tool, thanks for that, but doesnt work when I try to highlight results of the formula, its highlighting whole cell. Any solution for that ? example: if I type "Hi my name is Dan" in A1 and trying to highlight "Dan" - it works but If i textjoin B1+C1 and a result in A1 is "Hi my name is Dan" then it doesnt work as is highlighting whole sentence
You have no idea how much time this just saved me. Thank you!
Glad to hear that. Please subscribe and share
Excellent - thanks so much. Been looking for something that worked for hours.
Glad you like it. Please subscribe and be with us
Works perfectly, thanks a lot!
You're most welcome. Please subscribe and be with us.
Thank you so much! Can you give me the code for highlight all of the words from a wordlist within cells. I mean, i want to colour many different words at the same time
Can we make it so it isn't case sensitive?
Sub HighlightLängdInColumnQ()
' This macro highlights occurrences of the word "längd" (case-insensitive) in each cell in column Q.
' Disable screen updating to improve performance
Application.ScreenUpdating = False
' Declare variables
Dim targetCell As Range ' The cell in column Q where "längd" will be searched and highlighted
Dim searchText As String ' The text string to be highlighted
Dim tempString As String ' Temporary string to keep track of the processed text
Dim startIdx As Long ' Starting index for highlighting
Dim occurrenceCount As Long ' Number of occurrences found in each cell
' Set the text string to "längd"
searchText = "längd"
' Calculate the length of the search text
Dim searchTextLength As Long
searchTextLength = Len(searchText)
' Loop through each cell in column Q within the selected range
For Each targetCell In Range("Q:Q").Cells
If Not IsEmpty(targetCell) Then
With targetCell
' Convert cell content and search text to lowercase for case-insensitive comparison
Dim cellContent As String
cellContent = LCase(targetCell.Value)
Dim searchLower As String
searchLower = LCase(searchText)
' Find the number of occurrences of "längd" (case-insensitive) in the cell
occurrenceCount = UBound(Split(cellContent, searchLower))
' Check if there is at least one occurrence
If occurrenceCount > 0 Then
' Initialize the temporary string
tempString = ""
' Loop through each occurrence
For startIdx = 0 To occurrenceCount - 1
' Concatenate the text before the occurrence to the temporary string
tempString = tempString & Split(cellContent, searchLower)(startIdx)
' Highlight the current occurrence of "längd" (preserving original case)
.Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Font.ColorIndex = 3 ' Red color
' Concatenate the search text to the temporary string
tempString = tempString & Mid(targetCell.Value, Len(tempString) + 1, searchTextLength)
Next startIdx
End If
End With
End If
Next targetCell
' Re-enable screen updating
Application.ScreenUpdating = True
End Sub
Thank you brother, very good I tried it's working well❤❤❤❤
Glad you like it. Please subscribe and share
Thanks bro.
Any time
Do you have a video like this that would hide or delete text from a sentence? So instead of highlighting excel, it would delete the word?
Change the following line from the code:
.Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Font.ColorIndex = 5
To This:
.Characters(Start:=Len(tempString) + 1, Length:=searchTextLength).Delete
Hi its great tool, thanks for that, but doesnt work when I try to highlight results of the formula, its highlighting whole cell. Any solution for that ?
example:
if I type "Hi my name is Dan" in A1 and trying to highlight "Dan" - it works
but If i textjoin B1+C1 and a result in A1 is "Hi my name is Dan" then it doesnt work as is highlighting whole sentence
Where is code plx give link
Check video description