+ Reply to Thread
Results 1 to 5 of 5

Macro To Change Cell Color When Value Changes

Hybrid View

  1. #1
    carl
    Guest

    Macro To Change Cell Color When Value Changes

    I have a spreadsheet that is tracking stock prices. The cell with the price
    is fed by a DDE link.


    Stock Price
    AIG 100
    AXP 100
    AMAT 100
    AMGN 100
    AMD 100

    I am trying to create a visual monitoring tool. I was hoping to have the
    cell (ColB) change color (any color will do) everytime the price changes.

    For example, if the cell initially is no color, on the first change, color
    switches to green, on the next change, back to no color, on the 3rd price
    change, back to green etc.

    Is this type of thing possible ?

    Thank you in advance.

  2. #2
    JE McGimpsey
    Guest

    Re: Macro To Change Cell Color When Value Changes

    One way:

    Put this in your worksheet code module (right-click the worksheet tab
    and choose View Code):

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Const sRANGE As String = "B2:B100"
    Const nCOLORINDEX As Long = 10 'Green
    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(.Cells, Range(sRANGE)) Is Nothing Then
    With .Interior
    .ColorIndex = IIf(.ColorIndex = nCOLORINDEX, _
    xlColorIndexNone, nCOLORINDEX)
    End With
    End If
    End With
    End Sub


    In article <[email protected]>,
    carl <[email protected]> wrote:

    > I have a spreadsheet that is tracking stock prices. The cell with the price
    > is fed by a DDE link.
    >
    >
    > Stock Price
    > AIG 100
    > AXP 100
    > AMAT 100
    > AMGN 100
    > AMD 100
    >
    > I am trying to create a visual monitoring tool. I was hoping to have the
    > cell (ColB) change color (any color will do) everytime the price changes.
    >
    > For example, if the cell initially is no color, on the first change, color
    > switches to green, on the next change, back to no color, on the 3rd price
    > change, back to green etc.
    >
    > Is this type of thing possible ?
    >
    > Thank you in advance.


  3. #3
    carl
    Guest

    Re: Macro To Change Cell Color When Value Changes

    Thank you very much.

    I tried this out but could not get it to work . I have a formula in ColB.
    Does that make a difference ?

    "JE McGimpsey" wrote:

    > One way:
    >
    > Put this in your worksheet code module (right-click the worksheet tab
    > and choose View Code):
    >
    > Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    > Const sRANGE As String = "B2:B100"
    > Const nCOLORINDEX As Long = 10 'Green
    > With Target
    > If .Count > 1 Then Exit Sub
    > If Not Intersect(.Cells, Range(sRANGE)) Is Nothing Then
    > With .Interior
    > .ColorIndex = IIf(.ColorIndex = nCOLORINDEX, _
    > xlColorIndexNone, nCOLORINDEX)
    > End With
    > End If
    > End With
    > End Sub
    >
    >
    > In article <[email protected]>,
    > carl <[email protected]> wrote:
    >
    > > I have a spreadsheet that is tracking stock prices. The cell with the price
    > > is fed by a DDE link.
    > >
    > >
    > > Stock Price
    > > AIG 100
    > > AXP 100
    > > AMAT 100
    > > AMGN 100
    > > AMD 100
    > >
    > > I am trying to create a visual monitoring tool. I was hoping to have the
    > > cell (ColB) change color (any color will do) everytime the price changes.
    > >
    > > For example, if the cell initially is no color, on the first change, color
    > > switches to green, on the next change, back to no color, on the 3rd price
    > > change, back to green etc.
    > >
    > > Is this type of thing possible ?
    > >
    > > Thank you in advance.

    >


  4. #4
    JE McGimpsey
    Guest

    Re: Macro To Change Cell Color When Value Changes

    Yes, that makes a difference - Worksheet_Change() only fires when a
    cell's value is changed manually or via link.

    Hard to tell what to change without knowing how your data is input...

    In article <[email protected]>,
    carl <[email protected]> wrote:

    > I tried this out but could not get it to work . I have a formula in ColB.
    > Does that make a difference ?


  5. #5
    carl
    Guest

    Re: Macro To Change Cell Color When Value Changes

    Thank you again. The price data in ColB is coming from a "DDE Link". This is
    a "formula" that reads in streaming data from a data source.

    Does that clarify ?

    "JE McGimpsey" wrote:

    > Yes, that makes a difference - Worksheet_Change() only fires when a
    > cell's value is changed manually or via link.
    >
    > Hard to tell what to change without knowing how your data is input...
    >
    > In article <[email protected]>,
    > carl <[email protected]> wrote:
    >
    > > I tried this out but could not get it to work . I have a formula in ColB.
    > > Does that make a difference ?

    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1