Hello,
I have the code below to change the color of the customer ID from black to red. I'm not sure what's wrong with the code but it only works on some worksheets. I need to keep the formatting the same for the first 3 lines (times new roman size 12, black and bolded), but somehow it changes them to arial, size 11, black and sometimes red (basically same as customer ID), and it also doesn't always change the customer ID to red. Is there anyway to make the code work for all the different project files? Like maybe input the prefix in a form or dialog box and have the code find it in the merged cell and change its color and all the characters that follow? I also don't intend to keep the macro in the project workbooks. Could someone please help? Thank you in advance!
For some background:
- A1:F1 is a merged cell
- the length of the prefixes vary (at least 1 character) and there's really no pattern to associate with the project name either
- The prefixes are always followed by a dash "-"
- The numbers are always 3 digits (ie. 001 - 999). So the customer ID format is "PREFIX-001" as an example.
- Customers may be an individual or an institution so they may have other characters (ie. periods, dashes, commas, etc.) and numbers in their names.
workbook 1 = Project Name (ie. Houston) with 200+ worksheets. Same customer ID "TX-###" prefix across all worksheets
workbook 2 = Project Name (ie. Miami) with 200+ worksheets. Same customer ID "FLORIDA-###" prefix across all worksheets
workbook 3 = Project Name (ie. Los Angeles) with 200+ worksheets. Same customer ID "LA-###" prefix across all worksheets
workbook 4 = Project Name (ie. Chicago) with 200+ worksheets. Same customer ID "CHI-###" prefix across all worksheets
default format:
format needed:
I have the code below to change the color of the customer ID from black to red. I'm not sure what's wrong with the code but it only works on some worksheets. I need to keep the formatting the same for the first 3 lines (times new roman size 12, black and bolded), but somehow it changes them to arial, size 11, black and sometimes red (basically same as customer ID), and it also doesn't always change the customer ID to red. Is there anyway to make the code work for all the different project files? Like maybe input the prefix in a form or dialog box and have the code find it in the merged cell and change its color and all the characters that follow? I also don't intend to keep the macro in the project workbooks. Could someone please help? Thank you in advance!
For some background:
- A1:F1 is a merged cell
- the length of the prefixes vary (at least 1 character) and there's really no pattern to associate with the project name either
- The prefixes are always followed by a dash "-"
- The numbers are always 3 digits (ie. 001 - 999). So the customer ID format is "PREFIX-001" as an example.
- Customers may be an individual or an institution so they may have other characters (ie. periods, dashes, commas, etc.) and numbers in their names.
workbook 1 = Project Name (ie. Houston) with 200+ worksheets. Same customer ID "TX-###" prefix across all worksheets
workbook 2 = Project Name (ie. Miami) with 200+ worksheets. Same customer ID "FLORIDA-###" prefix across all worksheets
workbook 3 = Project Name (ie. Los Angeles) with 200+ worksheets. Same customer ID "LA-###" prefix across all worksheets
workbook 4 = Project Name (ie. Chicago) with 200+ worksheets. Same customer ID "CHI-###" prefix across all worksheets
default format:
format needed:
VBA Code:
Sub Color2()
Dim Position As Integer, Letters As Integer
Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
WS.Activate
Range("A1:F1").Select
Position = InStrRev(ActiveCell.Text, vbLf)
Letters = Len(ActiveCell.Text) - Position
If Position > 0 Then
With ActiveCell.Characters(Start:=Position + 1, Length:=Letters)
.Font.Color = vbRed
End With
End If
Next WS
MsgBox "Done."
End Sub