仕事に関係する情報のメモ 技術、プロジェクト管理など

水曜日, 2月 25, 2009

Excelで特定のセルに値が入力されたら、範囲指定してセルの色を変えるサンプル

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x, y As Integer
x = Target.Column
y = Target.Row

If Target.Column = 14 And Target <> "" Then '値が入っているなら
Range(Cells(Target.Row, 8), Cells(Target.Row, 15)).Select
With Selection.Interior
.ColorIndex = 48
.Pattern = xlSolid
End With
Else
Range(Cells(Target.Row, 8), Cells(Target.Row, 15)).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlSolid
End With
End If

Cells(y + 1, x).Select

End Sub

0 件のコメント: