2016-04-23 17 views
0

私のコードに問題があります。 Empty Cellは認識されません。詳細についてはセルが空の場合、条件

条件は、「セルが空の場合、現在のセルの上のセル内のテキストのフォントを変更する他に、リピート」である

Sub lastprice() 
    Dim price As String 
    Do 
     Selection.Find.ClearFormatting 
     With Selection.Find.Font 
      .Size = 11 
      .Bold = True 
     End With 
     With Selection.Find 
      .Text = "last price (" 
      .Forward = True 
      .Wrap = wdFindStop 
      .Format = True 
     End With 
     Selection.Find.Execute 

     If Selection.Find.Found = False Then 
      Exit Do 
     Else 
      Selection.MoveRight Unit:=wdCell 
      price = Trim(Selection.Text) 

      If price <> "" Then ' I think there is some problem 
       Selection.MoveLeft Unit:=wdCell, Count:=2 
       Selection.Font.Name = "Cambria" 
       Selection.MoveDown Unit:=wdLine, Count:=1 
      Else 
      End If 
     End If 
    Loop 
End Sub 

それが必要

をチェック条件で表の第2画像によって、より精巧な

答えて

1

私はデバッガでコードを実行し、実行しておき、priceが何であるかを調べました。文字コード13のセルマーカーが含まれていることが判明しました。したがって、Wordの空のセルには何かが含まれています。

If mid(price,1,1) <> Chr(13) Then 
+0

私はループに関するより具体的な2番目の画像を追加しました –

0

編集後:以下に、あなたのif文は変更し@paulのオギルビー私にとって

If mid(price,1,1) = Chr(13) Then 

作品、私はここで

=にロジック <>を変更するコード

を働いています
Sub lastprice() 
Dim price As String 
Do 
Selection.Find.ClearFormatting 
With Selection.Find.Font 
    .Size = 11 
    .Bold = True 
End With 
With Selection.Find 
    .Text = "last price (" 
    .Forward = True 
    .Wrap = wdFindStop 
    .Format = True 
End With 
Selection.Find.Execute 
If Selection.Find.Found = False Then 
    Exit Do 
    Else 
    Selection.MoveRight Unit:=wdCell 
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend 
    price = Trim(Selection.Text) 
    If Mid(price, 1, 1) = Chr(13) Then 
    Selection.MoveLeft Unit:=wdCell, Count:=2 
    Selection.Font.Name = "Cambria" 
    Selection.MoveDown Unit:=wdLine, Count:=1 
    Else 
    Selection.MoveRight Unit:=wdCharacter, Count:=1 
    End If 
    End If 
Loop 
End Sub 
関連する問題