Colour string with VBA

jacob11

New Member
Joined
Oct 28, 2022
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
VBA: Color all emails if any in cells of column A to green.
I have thousands of rows with emails in the cells of column A.
How can I force color all emails in green and copy them into respective rows of column B?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Not sure I am understanding completely. Suggest you post sample of 8-10 records and a mocked up solution. No pictures. Use XL2BB
 
Upvote 0
Here it is

keynote1 - Copy.xlsm
A
1
2Colour string with VBA
3
4VBA: Color all emails. 12345&@1_2@co.cn if any in cells xyz@wzy.com xyz@wzy.com of column A to green.
5
6
7
8I have thousands of 12345&@1_2@co.cn rows with emails in the cells of column A. xyz@wzy.com
9
10
11How can I force color all emails 12345&@1_2@co.cn in green and copy 12345&@1_2@co.cn them into respective rows of column B? 12345&@1_2@co.cn
Input


keynote1 - Copy.xlsm
AB
1
2
3VBA: Color all emails. 12345&@1_2@co.cn if any in cells xyz@wzy.com xyz@wzy.com of column A to green.12345&@1_2@co.cn, xyz@wzy.com, xyz@wzy.com
4
5
6
7I have thousands of 12345&@1_2@co.cn rows with emails in the cells of column A. xyz@wzy.com12345&@1_2@co.cn, xyz@wzy.com
8
9
10How can I force color all emails 12345&@1_2@co.cn in green and copy 12345&@1_2@co.cn them into respective rows of column B? 12345&@1_2@co.cn12345&@1_2@co.cn, 12345&@1_2@co.cn, 12345&@1_2@co.cn
Output
 
Upvote 0
Welcome to the MrExcel board!

Try this with a copy of your workbook.

VBA Code:
Sub ColourEmailsAndCopy()
  Dim a As Variant, b As Variant, Bits As Variant, Bit As Variant
  Dim i As Long, p As Long
  
  Application.ScreenUpdating = False
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To UBound(a), 1 To 1)
    For i = 1 To UBound(a)
      p = 1
      Bits = Split(a(i, 1))
      For Each Bit In Bits
        If InStr(1, Bit, "@") > 0 Then .Cells(i).Characters(p, Len(Bit)).Font.Color = vbGreen
        p = p + Len(Bit) + 1
      Next Bit
      b(i, 1) = Join(Filter(Bits, "@"), ", ")
    Next i
    With .Offset(, 1)
      .Value = b
      .Font.Color = vbGreen
    End With
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Can I delete all words in a particular font color?
The cells may have multiple words in different font colors.
 
Upvote 0
Can I delete all words in a particular font color?
The cells may have multiple words in different font colors.
More details? Sample data 'before' and 'after'?
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top