+ Reply to Thread
Results 1 to 1 of 1

VBA: Script to change text color if a change is made

Hybrid View

  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    NJ, US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Exclamation VBA: Script to change text color if a change is made

    Hello,

    I have this code (see below), the code changes new text entered to blue, but as soon as you click enter, the text in the cell is treated as old, so if you go again into the cell and make another change, it will change the text to black and only the new change to blue. I need it to continue changing to blue and keep recent changes in blue.

    Dim oldText As String
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim oldIndex As Integer
        Dim newIndex As Integer
        Dim rng As Range
        
        oldIndex = 1
        Set rng = Me.Range("A9:L300")
        
        If Target.Text <> "" And Not Intersect(Target, rng) Is Nothing Then
            For newIndex = 1 To Len(Target.Text)
                If Mid(Target.Text, newIndex, 1) = Mid(oldText, oldIndex, 1) Then
                    Target.Characters(newIndex, 1).Font.ColorIndex = 1
                    oldIndex = oldIndex + 1
                Else
                    Target.Characters(newIndex, 1).Font.ColorIndex = 5
                End If
            Next newIndex
        End If
    End Sub
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
            oldText = Target.Text
        End If
    End Sub
    Last edited by hector.febus; 03-06-2014 at 02:15 PM. Reason: Change title

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA: Script that changes new text to another color
    By hector.febus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-24-2014, 08:20 AM
  2. script to write 1's and zero's for cell color
    By NPeters in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2010, 01:52 PM
  3. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM
  4. Save As Macro Script
    By Neal in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2006, 11:10 AM
  5. [SOLVED] when i save xls file, debug script is running and canno't save fil
    By Imtiaz in forum Excel General
    Replies: 1
    Last Post: 07-16-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1