2014-04-19 2 views
0

"ean"과 같은 단어가 있으면 모든 셀을 검사합니다. 그런 다음 글꼴 문자열을 빨간색으로 표시하고 글꼴 스타일을 굵게 표시하고 싶습니다. 모든 것이 잘 작동하지만 문제는 i = 460 후에 pos가 항상 0입니다. InStr의 시작 값에 대한 제한을 찾지 못했습니다. 여기InStr 시작 매개 변수가 갑자기 0으로 시작합니다.

InStr([start], string, substring, [compare]) 

내 코드 :

For a = 2 To lastRow 
     Text = LCase(Cells(a, 11).Value) 
     TextLength = Len(Text) 
     If Text Like "* ean[!A-Za-z0-9]*" Then 
      korrektur = TextLength Mod 3 
      TextLength = TextLength - korrektur 
      Iteration = TextLength/3 
       For i = 1 To Iteration 
        pos = InStr((i * 3), Text, "ean") 
        Cells(a, 11).Select 
          With ActiveCell.Characters(Start:=pos, Length:=3).Font 
          .Color = vbRed 
          .FontStyle = "bold" 
         End With 
        End If 
       Next i 
     Next a 

어떤 생각?

접견, YAB

+3

IF를 열 때 어디를 다시보고 END IF를 넣을 수 있습니까? 'If pos <= 0 Then'과 같은 줄을 잊어 버렸는지 확인하십시오. 왜냐하면 "ean"이 그 단어에 없다는 것도 분명히 있기 때문입니다. – Graffl

답변

0

시도해보십시오 End If 두 번째 For-loop 내부

For a = 2 To lastRow 
    Text = LCase(Cells(a, 11).Value) 
    TextLength = Len(Text) 
    If Text Like "* ean[!A-Za-z0-9]*" Then 
     korrektur = TextLength Mod 3 
     TextLength = TextLength - korrektur 
     Iteration = TextLength/3 
      For i = 1 To Iteration 
       pos = InStr((i * 3), Text, "ean") 
       Cells(a, 11).Select 
       With ActiveCell.Characters(Start:=pos, Length:=3).Font 
        .Color = vbRed 
        .FontStyle = "bold" 
       End With 
      Next i 
    End If 
Next a 

이었다!

관련 문제