+ Reply to Thread
Results 1 to 3 of 3

Conditional formatting or macros or vba?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-04-2014
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    136

    Conditional formatting or macros or vba?

    Trying to find a solution to see if there is a way to format the numbers in a sentence to the colour red??


    Example:

    If (A1=100) & (B1=120)

    ="Today i scored "&text(sum($A$1),"0.00")&" and tomorrow i will try for "&text(sum($B$1),"0.00")

    I would like the result to look like this:

    Today i scored 100 and tomorrow i will try for 120

    Any ideas?

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Conditional formatting or macros or vba?

    replace D1 with cell you want output
    Sub ConditionalText()
    
        Dim i, j, k As Integer
        
        Range("D1").Select
        
        ActiveCell.Formula = "Today i scored " & Format(Range("A1"), "0.00") & " and tomorrow i will try for " & Format(Range("B1"), "0.00")
        i = Len(ActiveCell)
        
        j = Len(Format(Range("A1"), "0.00"))
        k = Len(Format(Range("B1"), "0.00"))
        
        With ActiveCell.Characters(Start:=1, Length:=i).Font
            .Color = vbBlack
        End With
        With ActiveCell.Characters(Start:=15, Length:=j + 1).Font
            .Color = vbRed
        End With
        With ActiveCell.Characters(Start:=i - k, Length:=k + 1).Font
            .Color = vbRed
        End With
        
    End Sub
    Attached Files Attached Files
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    02-04-2014
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: Conditional formatting or macros or vba?

    That is really good thank you. i can put a button in to run the macros. Cheers

+ 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] Conditional formatting + macros
    By helpplease344 in forum Excel General
    Replies: 4
    Last Post: 05-16-2014, 03:42 PM
  2. [SOLVED] Help with Macros and/or Conditional Formatting.
    By Inez15 in forum Excel General
    Replies: 5
    Last Post: 11-08-2012, 01:11 PM
  3. Conditional formatting and macros.
    By johnfar in forum Excel General
    Replies: 0
    Last Post: 12-15-2011, 09:41 AM
  4. Conditional Formatting Macros
    By njadam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2011, 02:58 AM
  5. Conditional Formatting And Macros
    By Dominic_Hodgson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2007, 05:33 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