다음을 통해 공유


방법: 선택한 셀이 포함된 워크시트 행의 서식 변경

선택한 셀이 포함된 행 전체의 글꼴을 변경하여 굵은 텍스트로 표시되도록 할 수 있습니다.

적용 대상: 이 항목의 정보는 Excel 2007 및 Excel 2010의 문서 수준 프로젝트 및 응용 프로그램 수준 프로젝트에 적용됩니다. 자세한 내용은 Office 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

현재 행을 굵게 표시하고 굵게 표시된 행을 보통 글꼴로 바꾸려면

  1. 이전에 선택한 행을 추적하는 정적 변수를 선언합니다.

    Static previousRow As Integer = 0
    
    static int previousRow = 0;
    
  2. ActiveCell 속성을 사용하여 현재 셀에 대한 참조를 검색합니다.

    Dim currentCell As Excel.Range = Me.Application.ActiveCell
    
    Excel.Range currentCell = this.Application.ActiveCell;
    
  3. 활성 셀의 EntireRow 속성을 사용하여 현재 행을 굵은 글꼴로 지정합니다.

    currentCell.EntireRow.Font.Bold = True
    
    currentCell.EntireRow.Font.Bold = true; 
    
  4. previousRow의 현재 값이 0이 아닌지 확인합니다. 이 값이 0이면 이 코드가 처음으로 실행되는 것임을 나타냅니다.

    If previousRow <> 0 Then
    
    if (previousRow != 0)
    
  5. 현재 행은 이전 행과 달라야 합니다.

    If currentCell.Row <> previousRow Then
    
    if (currentCell.Row != previousRow)
    
  6. 이전에 선택한 행을 나타내는 범위에 대한 참조를 검색하고 해당 행을 보통 글꼴로 설정합니다.

    Dim rng As Excel.Range = DirectCast(ws.Rows(previousRow), Excel.Range)
    rng.EntireRow.Font.Bold = False
    
    Excel.Range rng = (Excel.Range)ws.Rows[previousRow, missing];
    rng.EntireRow.Font.Bold = false;
    
  7. 다음 전달에서 이전 행이 될 수 있도록 현재 행을 저장합니다.

    previousRow = currentCell.Row
    
    previousRow = currentCell.Row;
    

다음 예제에서는 전체 메서드를 보여 줍니다.

예제

Private Sub BoldCurrentRow(ByVal ws As Excel.Worksheet)

    ' Keep track of the previously bolded row.
    Static previousRow As Integer = 0

    ' Work with the current active cell.
    Dim currentCell As Excel.Range = Me.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 Then

        ' Make sure the current row is not the same as the previous row.
        If currentCell.Row <> previousRow Then

            Dim rng As Excel.Range = DirectCast(ws.Rows(previousRow), Excel.Range)
            rng.EntireRow.Font.Bold = False
        End If
    End If

    ' Store the new row number for the next pass.
    previousRow = currentCell.Row
End Sub
// 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, missing];
            rng.EntireRow.Font.Bold = false;
        }

    // Store the new row number for the next pass.
    previousRow = currentCell.Row;
}

참고 항목

작업

방법: 통합 문서에서 일정 범위에 스타일 적용

방법: 워크시트 간에 데이터 및 서식 복사

개념

워크시트 작업

Office 솔루션의 선택적 매개 변수