Sub CommentThem()
Dim cell As Range
Dim cmt As Comment
On Error Resume Next
Selection.ClearComments
On Error GoTo 0
For Each cell In Intersect(Selection, ActiveSheet.UsedRange)
If cell.Formula <> "" Then
cell.AddComment
cell.Comment.Visible = False
cell.Comment.Shape.AutoShapeType = msoShapeFlowchartAlternateProcess
cell.Comment.Shape.Fill.ForeColor.RGB = RGB(242, 242, 242)
On Error Resume Next 'fails on invalid formula
cell.Comment.Text Text:=cell.Address(0, 0) & _
" Value: " & cell.Value & chr(10) & _
" Formula: " & cell.Formula & chr(10) & _
" Format: " & cell.NumberFormat '= '"General" ' "0.000000"
cell.Comment.Shape.ScaleWidth 1.25, msoFalse, msoScaleFromTopLeft
cell.Comment.Shape.ScaleHeight 0.69, msoFalse, msoScaleFromTopLeft
On Error GoTo CodeError
With cell.Comment.Shape.TextFrame.Characters.Font
.Name = "Calibri"
.Size = 9
.Color = RGB(0, 75, 145) '-7255296
.Bold = True
End With
On Error GoTo 0
End If
Next cell
CodeError:
' MsgBox "Error with Comment Format"
End Sub
ASKER
ASKER
ASKER
Sub Delete_All_Names_with_RefersTo_Errors()
Dim xRow As Long
Dim xName As name
Dim xResponse As Long
xResponse = MsgBox("About to delete all Names whose RefersTo contains an error from """ & ActiveWorkbook.name & """." _
& Chr(10) & "('OK' to continue, 'Cancel' to quit.)", vbOKCancel, "Delete_All_Names_with_RefersTo_Errors")
If xResponse = 2 Then
MsgBox "User chose not to continue. Run terminated."
Exit Sub
End If
Sheets.Add
Range("A1:L1") = Array("No.", "Name", "RefersTo", "Comment", "Macro Type", "Category", "RefersTo Range", "Short-Cut Key", "Valid Book Parameter", "Value", "Visible", "Deleted?")
xRow = 2
Application.ScreenUpdating = False
For Each xName In ActiveWorkbook.Names
With xName
Cells(xRow, 1) = .Index
Cells(xRow, 2) = .name
Cells(xRow, 3) = " " & .RefersTo
Cells(xRow, 4) = " " & .Comment
Cells(xRow, 5) = " " & .MacroType
Application.DisplayAlerts = False
On Error Resume Next
Cells(xRow, 6) = " " & .Category
Cells(xRow, 7) = " " & .RefersToRange
Cells(xRow, 8) = " " & .ShortcutKey
On Error GoTo 0
Application.DisplayAlerts = True
Cells(xRow, 9) = " " & .ValidWorkbookParameter
Cells(xRow, 10) = " " & .Value
Cells(xRow, 11) = " " & .Visible
If InStr(1, .RefersTo, "#") > 0 Then
On Error Resume Next
ActiveWorkbook.Names(.Index).Delete
If Err.Number <> 0 Then
Debug.Print .Index & " - " & .name & " - Error # " & CStr(Err.Number) & " " & Err.Description & " " & Err.Source
Cells(xRow, 12) = "Error - " & Err.Number
Err.Clear
Else
Cells(xRow, 12) = "Y"
End If
On Error GoTo 0
End If
xRow = xRow + 1
End With
Next xName
Application.ScreenUpdating = True
End Sub
Regards,ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
ASKER
I believe you understood correctly, and it worked like exactly as needed on the few that I tried.
Thanks,
Cook