我制作了一个宏,它将超链接从一列复制到另一列。
宏工作得很好但超链接在其中间包含'#'所以我们说:
https://website.com/nu#somethingsomething
使宏复制只是它的第一部分,即:
https://website.com/nu
如何使Excel忽略'#'(如果可能的话)和复制超链接的整个值?
VBA代码:
Sub MilestonesHyperlink()
For i = 2 To 62 'Number of rows
If Range("B" & i).Value <> "" And Range("A" & i).Value <> "" Then 'Copy from column B to A
Dim newLink As String
If Range("B" & i).Hyperlinks.Count = 1 Then
newLink = Range("B" & i).Hyperlinks(1).Address
Range("A" & i).Hyperlinks.Add anchor:=Range("A" & i), Address:=Range("A" & i)
Range("A" & i).Hyperlinks(1).Address = newLink
End If
End If
Next i
End Sub
答案 0 :(得分:1)
尝试将newlink
替换为:
newLink = Range("B" & i).Hyperlinks(1).Address + "#" + Range("B" & i).Hyperlinks(1).SubAddress