[Webinar] Streamline your web hosting managementRegister Today


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

Posted on 2004-10-21
Medium Priority
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
Question by:zachvaldez
LVL 53

Accepted Solution

Dhaest earned 260 total points
ID: 12369982
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
 End With

Assisted Solution

PePi earned 240 total points
ID: 12371719
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

Author Comment

ID: 12373405
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)

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

590 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