Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can change the font of an entire row that contains a selected cell so that the text is bold.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
Declare a static variable to keep track of the previously selected row.
Retrieve a reference to the current cell using the ActiveCell property.
Style the current row bold using the EntireRow property of the active cell.
Ensure that the current value of previousRow
is not 0. A 0 (zero) indicates that this is the first time through this code.
Ensure that the current row is different from the previous row.
Retrieve a reference to a range that represents the row that was previously selected, and set that row to not be bold.
Store the current row so that it can become the previous row on the next pass.
The following example shows the complete method.
// Keep track of the previously bolded row.
static int previousRow = 0;
private void BoldCurrentRow(Excel.Worksheet ws)
{
// Work with the current active cell.
Excel.Range currentCell = this.Application.ActiveCell;
// Bold the current row.
currentCell.EntireRow.Font.Bold = true;
// If a pass has been done previously, make the old row not bold.
// Make sure previousRow is not 0 (otherwise this is your first pass through).
if (previousRow != 0)
// Make sure the current row is not the same as the previous row.
if (currentCell.Row != previousRow)
{
Excel.Range rng = (Excel.Range)ws.Rows[previousRow];
rng.EntireRow.Font.Bold = false;
}
// Store the new row number for the next pass.
previousRow = currentCell.Row;
}
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!