Consulting

Results 1 to 3 of 3

Thread: Solved: Instr & bold

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Solved: Instr & bold

    Hello everyone, I am having a problem with the following code:

    [vba]
    If mm = 1 Then
    With ActiveSheet.Range(Cells(January, 2), Cells(January, 15))
    Set cell1 = .Find(dd, LookIn:=xlValues, lookat:=xlPart)
    If Not cell1 Is Nothing Then
    firstaddress = cell1.Address
    Call TestForComments

    If q = "No Comment" Then
    Range(firstaddress).AddComment ("Training On " & mydate)
    Range(firstaddress).Interior.ColorIndex = 6
    With Range(firstaddress)
    .Characters(InStr(cell1, ddd)).Font.Bold = True
    End With
    End If

    If q = "Has Comment" Then
    cmt = Range(firstaddress).Comment.Text
    Range(firstaddress).ClearComments
    Range(firstaddress).AddComment (cmt & ", Training On " & mydate)
    Range(firstaddress).Interior.ColorIndex = 6
    With Range(firstaddress)
    .Characters(InStr(cell1, ddd)).Font.Bold = True
    End With
    End If
    End If
    End With
    End If
    [/vba]

    I have dates in cells as text such as "1,15,29", "12,26" etc. which represent the dates of the month. What I am doing is finding a date adding a comment in the cell and trying to make the specific date within the cell bold. What is happening is if the first date in the cell is that date, all of the dates in the cell will turn bold and if the second date is the selected date, both the second and third date will turn bold. I can't seem to get a handle on the problem. I'm attaching the file if you need it to respond and the code I am dealing with is in Module06 in sub Trainingdates.

    Thanks
    Gary

  2. #2
    VBAX Regular
    Joined
    Oct 2009
    Location
    Fremont, CA
    Posts
    72
    Location

    Try this

    You are using the Characters property without the Length variable. The syntax for the Characters property is

    [vba]
    Characters(Start, Length)
    [/vba]

    When you omit the Length parameter VBA assumes that you are referring to all characters from the Start position on to the end. If I correctly understand your code the following syntax should produce the desired result:

    [vba]
    Characters(InStr(cell1, ddd), Len(ddd)).Font.Bold = True

    [/vba]
    Hope this helped,
    Rolf Jaeger
    SoarentComputing
    Software Central

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Thanks Rolf, I missed that.

    Gary

Posting Permissions

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