PDA

View Full Version : Solved: Instr & bold



zoom38
11-17-2009, 06:02 PM
Hello everyone, I am having a problem with the following code:


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


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

RolfJ
11-17-2009, 07:11 PM
You are using the Characters property without the Length variable. The syntax for the Characters property is


Characters(Start, Length)


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:


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

zoom38
11-17-2009, 09:58 PM
Thanks Rolf, I missed that.

Gary