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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0


'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?
 
Upvote 0
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...
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,917
Members
449,055
Latest member
KB13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top