K
kevinknight09
I am anything but an Excel or VB programmer. I knew I needed a macro
and using some others I found on the web I created the following:
==============================================
Sub auto_open()
' Run the macro DidCellsChange any time a entry is made in a
' cell in Sheet1.
ThisWorkbook.Worksheets("Sheet1").OnEntry = "DidCellsChange"
End Sub
Sub DidCellsChange()
Dim KeyCells As String
' Define which cells should trigger the KeyCellsChanged macro.
KeyCells = "C45, E45, H45, I45, M45, B47"
' If the Activecell is one of the key cells, call the
' KeyCellsChanged macro.
If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
Is Nothing Then KeyCellsChanged
End Sub
Sub KeyCellsChanged()
Dim Cell As Object
' If the values in C45,E45,H45,M45,B47 are greater than nil...
For Each Cell In Range("C45, E45, H45, M45, B47")
If Cell > "" Then
' Make the background color of the cell the 3rd color on the
' current palette.
Cell.Interior.ColorIndex = 3
Else
' Otherwise, set the background to none (default).
Cell.Interior.ColorIndex = 0
End If
Next Cell
===========================================
How is it possible to have the background color in cell A44 change to
Cell.Interior.ColorIndex = 3 instead of cell C45, E45, H45, M45, or
B47? I thought it would be as simple as changing line
Cell.Interior.ColorIndex = 3
to
Cell.Interior.ColorIndex("A44") = 3
but this causes the macro to crash and the debugger comes up. Again,
any assistance would be greatly appreciated.
Thank you all in advance.
Kevin Knight
and using some others I found on the web I created the following:
==============================================
Sub auto_open()
' Run the macro DidCellsChange any time a entry is made in a
' cell in Sheet1.
ThisWorkbook.Worksheets("Sheet1").OnEntry = "DidCellsChange"
End Sub
Sub DidCellsChange()
Dim KeyCells As String
' Define which cells should trigger the KeyCellsChanged macro.
KeyCells = "C45, E45, H45, I45, M45, B47"
' If the Activecell is one of the key cells, call the
' KeyCellsChanged macro.
If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
Is Nothing Then KeyCellsChanged
End Sub
Sub KeyCellsChanged()
Dim Cell As Object
' If the values in C45,E45,H45,M45,B47 are greater than nil...
For Each Cell In Range("C45, E45, H45, M45, B47")
If Cell > "" Then
' Make the background color of the cell the 3rd color on the
' current palette.
Cell.Interior.ColorIndex = 3
Else
' Otherwise, set the background to none (default).
Cell.Interior.ColorIndex = 0
End If
Next Cell
===========================================
How is it possible to have the background color in cell A44 change to
Cell.Interior.ColorIndex = 3 instead of cell C45, E45, H45, M45, or
B47? I thought it would be as simple as changing line
Cell.Interior.ColorIndex = 3
to
Cell.Interior.ColorIndex("A44") = 3
but this causes the macro to crash and the debugger comes up. Again,
any assistance would be greatly appreciated.
Thank you all in advance.
Kevin Knight