How to only format a part of a string in a cell with VBA

后端 未结 1 1683
花落未央
花落未央 2021-01-21 04:00

The goal is to change these values A10,B10,C10,D10,E10,F10,G10,H10,I10,J1 to a font blue color.

For example, \"Yonge St A10, B10\", only A10 and B10 should be in a blue

相关标签:
1条回答
  • 2021-01-21 04:20

    You need to specify the character start and length within the cell, that you want to format:

    Therefore replace

    Cells(i, 2).Font.Color = RGB(0, 0, 255)
    

    with

    Cells(i, 2).Characters(Start:=outcomeNum, Length:=Len(seq)).Font.Color = RGB(0, 0, 255)
    

    Just because I noticed: seq is missing in declaration.

    Dim seq As Variant
    

    I recommend using Option Explicit to avoid forgetting any declarations and minimizing errors due to typos in variable names.

    0 讨论(0)
提交回复
热议问题