2013-02-01 75 views

回答

1

您需要創建一個宏,以查找當前工作表中有多少行,然後遍歷從工作表底部到頂部的行,檢查第一列的Font.Bold屬性行被設置爲false。如果是這樣,你刪除該行。

對我來說,以下工作:

Sub DeleteUnboldRows() 
    Dim lastRow As Long 
    Dim currentRow As Long 

    'Select All the rows in the active worksheet 
    lastRow = ActiveSheet.UsedRange.Rows.Count 

    ' Iterate through each row from the bottom to the top. 
    ' If we go the other way rows will get skipped as we delete unbolded rows! 
    For currentRow = lastRow To 1 Step -1 

     'Look at the cell in the first column of the current row 
     ' if the font is not bolded delete the row 
     If ActiveSheet.Rows(currentRow).Columns(1).Font.Bold = False Then 
      ActiveSheet.Rows(currentRow).Delete 
     End If 
    Next currentRow 
End Sub 

下面是Bold屬性的引用:http://msdn.microsoft.com/en-us/library/office/aa224034%28v=office.11%29.aspx

+0

非常感謝你這個完美!我試着編輯來的其他代碼,我發現在線刪除粗體行,但我無法得到它的工作。 – user2031261

+0

樂於幫助。如果您不介意,請將我的答案標記爲已接受? –

1
Sub deleteNonBolded() 

    Dim cell As Range 
    Dim selectRange As Range 

    For Each cell In Intersect(ActiveSheet.Range("A:A"), ActiveSheet.UsedRange) 
     If (cell.Font.Bold = False) Then 
      If selectRange Is Nothing Then 
       Set selectRange = cell 
      Else 
       Set selectRange = Union(cell, selectRange) 
      End If 
     End If 
    Next cell 

    selectRange.EntireRow.Delete 

End Sub 
相關問題