Solved

changing msflexgrid row to a different color if the number displays negative.

Posted on 2004-10-21
213 Views
Last Modified: 2013-12-26
Since I was able to display negative numbers in an msflexgrid,
 I would also like to display it in red for that row. How to do that?

Part of the code I'd like to insert the code... to change row color if negative

   With grdEquipData
        'Check if "Cost" and "Qty" are available
        If (Trim(.TextArray(.row * .Cols + 7)) <> "" And Trim(.TextArray(.row * .Cols + 3)) <> "") Then
            'Total Cost = Unit Cost * Qty
            .TextArray(.row * .Cols + 8) = FormatNumber((.TextArray(.row * .Cols + 3)) * Val((.TextArray(.row * .Cols + 7))), 2)
        End If
 end with
0
Question by:zachvaldez
    3 Comments
     
    LVL 53

    Accepted Solution

    by:
    With MSflexgrid there is no straight way to set color to a full row. You have to set color cell by cell. Lets say you have 5 columns and and want to set color of 4th row to yellow, then this is how you will do it:

    For intLoop=0 to 4
     With MSHFlexgrid1
      .Row=4
      .Col=intLoop
      .CellBackColor=vbYellow
     End With
    Next
    0
     
    LVL 6

    Assisted Solution

    by:PePi
    try this


    With grdEquipData
        .Row = r            'set the row you want to change the color
        for c = 0 to .Cols -1            'loops through all the columns in the row nd changes its color
            .Col = c
            .CellBackColor = vbRed
        next c
    End With

    hope this helps
    0
     

    Author Comment

    by:zachvaldez
    only when it is negative number though..
    i'd like the row to display color red...
    .TextArray(.row * .Cols + 8) = FormatNumber((.TextArray(.row * .Cols + 3)) * Val((.TextArray(.row * .Cols + 7))), 2)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now