我试图找到名称以_结尾的每个命名单元格,并且单元格的值为空。这是我用过的代码无济于事。 (msgbox只是为了帮助我查看它找到了多少。)如果你知道一种更好的方法(不必每次都做一次),_是要求细胞需要的,请告诉我。谢谢!
namedrange = 0
For Each cell In ActiveWorkbook.Names
If Right(cell.Name, 1) = "_" And cell.Value = "" Then
cell.Interior.ColorIndex = 3
namedrange = namedrange + 1
End If
Next cell
MsgBox namedrange
答案 0 :(得分:1)
试试这个:
Sub test()
Dim RangeName As Name
Dim namedrange As Long
namedrange = 0
For Each RangeName In ActiveWorkbook.Names
If Right(RangeName.Name, 1) = "_" And Range(RangeName).Value = "" Then
Range(RangeName).Interior.ColorIndex = 3
namedrange = namedrange + 1
End If
all = all + 1
Next RangeName
MsgBox namedrange
End Sub
答案 1 :(得分:0)
解决方案:
requiredmissing = 0
Dim RangeName As Name
Dim namedrange As Long
For Each RangeName In ActiveWorkbook.Names
If Right(RangeName.Name, 1) <> "_" Then GoTo skipthisone
If Range(RangeName.Name).Value = "" Then
Range(RangeName.Name).Interior.ColorIndex = 6
requiredmissing = requiredmissing + 1
Else
Range(RangeName.Name).Interior.ColorIndex = 0
End If
all = all + 1
skipthisone:
Next RangeName