我想创建一个新表以显示所有具有超链接外包的单元,但是在此仅显示最后一个结果,而不是所有结果。
Sub test()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim Ws As Worksheet, Rng As Range
Dim r As Long
Dim s As Byte
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Hyperlink").Delete
On Error GoTo 0
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "Hyperlink"
For Each Ws In Worksheets
r = 1
For Each Rng In Ws.UsedRange
If InStr(Rng.FormulaLocal, "[") Then
Rng.Interior.ColorIndex = 6
Cells(r, 2).Value = Ws.Name
Cells(r, 3).Value = Rng.Address
End If
Next Rng
r = r + 1
Next Ws
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "Hoan thanh.", , "Nguyen Duc Thinh - 093 23456 19"
End Sub
答案 0 :(得分:2)
您最好在if语句内而不是外部增加变量r。
赞:
For Each Rng In Ws.UsedRange
If InStr(Rng.FormulaLocal, "[") Then
Rng.Interior.ColorIndex = 6
Cells(r, 2).Value = Ws.Name
Cells(r, 3).Value = Rng.Address
r = r + 1
End If
Next Rng