PDA

View Full Version : [SOLVED:] Highlight domain



KAMRAN AJ
03-14-2023, 03:10 AM
Hi, hope you are doing great
I need a dyanmic range for active sheet Excel VBA code
that highlight the email column domain and website column domain if the domains are same it hightlihght the same domain ,if the domains are not same dont hightlight or ignore.
i also have attached the screenshot .
I also attached a youtube link i which I explained what I want.https://www.youtube.com/watch?v=xH4o72w-xHw

georgiboy
03-14-2023, 03:44 AM
How about something like the attached?

KAMRAN AJ
03-14-2023, 04:06 AM
i just want to highlight domain not a entire row

KAMRAN AJ
03-14-2023, 04:08 AM
Excellent work

georgiboy
03-15-2023, 12:17 AM
Maybe the below for just the domain:

Sub test()
Dim rCell As Range
Dim tmp As String
Dim lStr As String, rStr As String

For Each rCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Cells
With rCell
lStr = Left(.Value, InStr(.Value, ".") - 1)
tmp = Left(.Offset(, 1), InStr(.Offset(, 1), ".") - 1)
rStr = Right(tmp, Len(tmp) - InStr(tmp, "@"))
If lStr = rStr Then
.Characters(InStr(.Value, lStr), Len(lStr)).Font.ColorIndex = 3
.Offset(, 1).Characters(InStr(.Offset(, 1), lStr), Len(lStr)).Font.ColorIndex = 3
End If
End With
tmp = vbNullString
Next rCell
End Sub

KAMRAN AJ
03-15-2023, 02:14 AM
oh it is
working for me

KAMRAN AJ
03-15-2023, 02:53 AM
I appreciate your work . and your code in working for me ,your work is excellent
Please make a changings in code,i want to match the domains of Column B(WEBSITE) with column K(Email)
Please check my screenshot or check my youtube guidance video
30636
https://www.youtube.com/watch?v=u5N3c2IMt6s

Aussiebear
03-15-2023, 03:35 AM
@Kamran AJ. Try making the changes yourself. In your initial example you were using columns A & B right? So when you look at Georgiboy's code what sticks out as defining Column A and Column B?

Hint 1. Since the below code defines the Range in Column A, what would you consider changing to make it reflect Column B?


For each rCell in Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Cells


Hint 2. The below code finds the value in Column B of the active row, so what would you change if the column you seek is 9 columns further to the right?


tmp =Left(.Offset(,1), Instr(.Offset(, 1), ".") -1)

georgiboy
03-15-2023, 03:36 AM
Maybe:

Sub test()
Dim rCell As Range
Dim tmp As String
Dim lStr As String, rStr As String

For Each rCell In Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row).Cells
With rCell
lStr = Left(.Value, InStr(.Value, ".") - 1)
tmp = Left(.Offset(, 9), InStr(.Offset(, 9), ".") - 1)
rStr = Right(tmp, Len(tmp) - InStr(tmp, "@"))
If lStr = rStr Then
.Characters(InStr(.Value, lStr), Len(lStr)).Font.ColorIndex = 3
.Offset(, 9).Characters(InStr(.Offset(, 9), lStr), Len(lStr)).Font.ColorIndex = 3
End If
End With
tmp = vbNullString
Next rCell
End Sub

KAMRAN AJ
03-15-2023, 06:09 AM
Thank you so much it is working for me