[[20050202130924]] 『.Weight = xlThin : OK .Weight = xlMedium : NG 』(ちょっかく) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『.Weight = xlThin : OK .Weight = xlMedium : NG なぜ?』(ちょっかく)

条件付き書式でセルの値が空でなかった場合に罫線を引かせたのですが、線を太くしようとマクロを作っています。

.Weight = xlThin を .Weight = xlMedium に変えればよいのだろうと変えたらエラーになってしまいました。何が悪いのでしょう?

マクロは以下のとおりです。どなたか、アドバイスなどお願いします。

    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
        Formula1:="0"
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium   'エラーになる なぜ?
        .ColorIndex = xlAutomatic
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With


 条件付書式には太線が無いからでしょう・・。
 条件付書式を無くしてマクロにしているのであれば、
    With Selection.Borders(xlEdgeLeft)
        .Weight = xlMedium
   End With
 だけで良いのじゃないですか。

 シートモジュールに貼り付けるものですが。
Private Sub Worksheet_Change(ByVal Target As Range)
'A1からC50の範囲のみを対象の場合
If Application.Intersect(Target, Range("A1:C50")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub  '複数セルは対象外
If IsEmpty(Target.Value) Then
    With Target.Borders
        .LineStyle = xlNone
    End With
Else
    With Target.Borders
        .Weight = xlMedium
    End With
End If
End Sub

 (川野鮎太郎)

コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.