用数据将超链接插入列

我正试图插入有数据的列A上的超链接。 例如,A1是标题; A2将是12345超链接http://123.1.1.1/?id=12345

目前我正在包含大约11000行的工作表上运行macros。 已经有一个小时了,还在运行…

此外,试图看看这个单一的macros可以在所有的工作表上工作。

下面是我的macros

Sub AddUrlSheet1() With Worksheets(1) Set R = ActiveSheet.Range("a2", ActiveSheet.Range("a2").End(xlDown)) R.Select For Each R In Selection.Cells .Hyperlinks.Add Anchor:=R, _ Address="http://123.1.1.1/" & R.Value Next R End With End Sub 

尝试这个:

 Sub AddUrlSheet1() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual ' Dim LastUsedRow As Long Dim r As Range, c As Range With ActiveSheet LastUsedRow = .Columns("A").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlFormulas, SearchDirection:=xlPrevious).Row Set r = .Range(.Cells(2, 1), .Cells(LastUsedRow, 1)) End With ' For Each c In r c.Hyperlinks.Add Anchor:=c, Address:="http://123.1.1.1/" & c.Value Next c Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub 

这将超链接添加到列A中当前具有值的所有单元格中。

而不是循环逐个单元格,使用Hyperlink()Formula来完成它。 如果您的R值在列A中,则会填入B列中的超链接。

 Sub t() Dim rng As Range ' Note: Update the `10` to match your lastRow Set rng = Range("B2:B" & ActiveSheet.Range("a2").End(xlDown).Row) rng.FormulaR1C1 = "=HYPERLINK(""http://123.1.1.1/""&RC[-1],""Link"")" End Sub 

如果你必须迭代你已经存在的数据,@ Chris的答案看起来不错。