Results 1 to 3 of 3

Thread: help for a highlighter

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    1

    Post help for a highlighter

    this is one of my first brush ups with VBA(and excel, for that matter), so I don't know much about the language.
    nycase, I'm supposed to write a macro that will check the text in a certain cell to see if there are any specific words(which I define), and turn them Red.

    I've thought of a way to do this, but I need to be able to define which a place within a cell. ex. if <> is a cell, then <Hello world, how are you today> I would need to say "from space 6 onwards check if...., then from space 13 onwards, check if....." etc.

    can anyone explain how to do this? thanks alot.

    if you know a good way of making this macro, please tell me that as well ^_~

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help for a highlighter

    Welcome to the Forums.

    So this will only check one cell, correct?

    Usually the easiest way to determine how to access something programmatically, you record a macro
    doing your task, stop it and check the generated code in the VBA IDE.

    Now, since your needing to do some searching in the cell before you do anything, it would be easier to just
    record a macro changing the cells backcolor. Then we can use that as astarting place.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help for a highlighter

    This should get you started. It highlights the word "World!" in cell C6.
    VB Code:
    1. Private Sub HighLightMe()
    2.     'C6 contains "Hello World!" and highlights "World!"
    3.     Dim iStart As Integer
    4.     ActiveSheet.Range("C6").Select
    5.     iStart = InStr(1, ActiveCell.Value, "World!")
    6.     If iStart > 0 Then
    7.         'Turn off coloring for any previous finds
    8.         Selection.Font.ColorIndex = xlAutomatic
    9.         'Turn on coloring for the found word (World!)
    10.         ActiveCell.Characters(Start:=iStart, Length:=iStart + Len("World!")).Font.ColorIndex = 3
    11.     End If
    12. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width