Conditional formatting: Format entire row based on single cell value and using defined names

Koekert

New Member
Joined
Apr 3, 2009
Messages
7
Hi all,

I'm kinda new in VB/VBA and I was wondering if the following is possible:

Currently I'm using a workbook, containing multiple sheets, to create a status overview. One of the sheet is used to list all open defects and contains information like unique ID, description, affected version, etc.

I would like to create a script that checks if the affected version matches with one of the two names defined (inserts->name->define). If not, the entire row should be formatted as bold, red.

I've tried the following but this only changes the single cell and the defined names are not used yet. Can anyone help?

Option Explicit
Dim mySheet, myCells
Dim curRow, curCol, curVal

Sub ConditionalFormat()

Set mySheet = ActiveWorkbook.Sheets("Issues")
Set myCells = mySheet.Cells

curRow = 2 'skip first row since this contains the header
curCol = 4 'check the affected version column

curVal = mySheet.Cells(curRow, curCol)

Do Until IsEmpty(curVal)

If curVal <> "Release" And curVal <> "HOME" Then 'Defined names should be used here
'ActiveCell.EntireRow.Select
'ActiveCell.EntireRow.Font.ColorIndex = 3

'Range(curRow: curRow).Font.ColorIndex = 3

myCells(curRow, curCol).Font.ColorIndex = 3
myCells(curRow, curCol).Font.Bold = True
End If

curRow = curRow + 1
curVal = mySheet.Cells(curRow, curCol)
Loop

End Sub
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Welcome to the Board.

I don't think you need a macro for that. Which column contains "affected version" and in what way do you want to match it with defined names? What are those names and what do they refer to?
 

Koekert

New Member
Joined
Apr 3, 2009
Messages
7
Welcome to the Board.

I don't think you need a macro for that. Which column contains "affected version" and in what way do you want to match it with defined names? What are those names and what do they refer to?
The column containing 'affected version' is column D. The workbook contains a sheet called 'Data'. This sheet contains data like team members, current release, available components, etc. I've made a define for the current release so that I only have to refer to 'Release' instead of the actual release ID.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Select the columns you want to format and choose Format|Conditional Formatting from the menu. For Condition 1 select Formula Is, enter:

=AND($D1<>Release,$D1<>HOME)

choose a Format and click OK twice.

The formula assumes that row 1 is the active row (change to suit) and that the names refer to a single cell.
 

Koekert

New Member
Joined
Apr 3, 2009
Messages
7
Thank you for the reply; works great! However; i'm eager to learn and I still would like to know how this can be done using VBA. Am I on the right way?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
In VBA the test would be:

Code:
If curVal <> Range("Release").Value And curVal <> Range("HOME").Value
 

Koekert

New Member
Joined
Apr 3, 2009
Messages
7


'ActiveCell.EntireRow.Select

'ActiveCell.EntireRow.Font.ColorIndex = 3

'Range(curRow: curRow).Font.ColorIndex = 3

myCells(curRow, curCol).Font.ColorIndex = 3
myCells(curRow, curCol).Font.Bold = True
Again thanks for the response! The If-statement was not my bigest problem, but detecting the current row and then change it's entire format is. e.g. Range(variable:variable).Font.ColorIndex does not seem to work so I think the range should be used otherwise. Any suggestions?
 

Koekert

New Member
Joined
Apr 3, 2009
Messages
7
I'll check tomorrow but my guess is that this will only 'highlight' the cell containing the value (either HOME or release) while the whole row (at least within the range A to F) is requested...
 

Forum statistics

Threads
1,082,155
Messages
5,363,472
Members
400,741
Latest member
MachoDrove

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top