我试图清除一些细胞的内容。在“Adjs”范围内,如果单元格的字体是粗体,那么如果单元格不是粗体,那么我将不会清除该行。我会清除整行......
但是当我运行它时,它一直给我这个错误“应用程序定义的或对象定义的错误”
谢谢
Sub CL()
Application.Calculation = xlCalculationManual
ThisWorkbook.Activate
Sheets(1).Select
For Each c In Range("Adjs").Cells
If c.Font.Bold = false Then
Range(c.Offset(0, -6), c.Offset(0, -1)).ClearContents
End If
Next
End Sub
答案 0 :(得分:0)
尝试以下代码:
Sub CL()
Dim lCalMode As Long, c As Range
lCalMode = Application.Calculation
Application.Calculation = xlCalculationManual
On Error Resume Next
With ThisWorkbook.Names("Adjs").RefersToRange
.Worksheet.Activate
.Worksheet.Unprotect
For Each c In .Cells
If c.Font.Bold = False Then
With Range(c.Offset(0, -6), c.Offset(0, -1))
Debug.Print "Clearing " & .Address
.ClearContents
End With
End If
Next
.Worksheet.Protect
End With
Application.Calculation = lCalMode
End Sub