我正在使用此代码段将指向另一个工作簿的链接放入我自己的代码:
Sub legg_inn_lekkjer()
Dim i As Long
Call deaktiver
For i = 0 To 740
Loktider.Range("C4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C6"
Loktider.Range("D4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C5"
Loktider.Range("E4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C16"
Loktider.Range("F4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C15"
Loktider.Range("G4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C6"
Loktider.Range("H4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C5"
Loktider.Range("I4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C16"
Loktider.Range("J4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C15"
Next
Call reaktiver
End Sub
Sub deaktiver()
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
' ActiveSheet.DisplayPageBreaks = True 'note this is a sheet-level setting
End Sub
Sub reaktiver()
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
' ActiveSheet.DisplayPageBreaks = True 'note this is a sheet-level setting
End Sub
它可以正常工作,但需要很长时间才能运行。它可能不会成为一个问题,因为我不需要经常更新链接地址,但我仍然想知道是否有更有效的方法来执行此操作,使用某种相对引用例如,一次输入每列的地址?相当多的谷歌搜索表明"没有",但我认为要问它不会有什么坏处。
答案 0 :(得分:1)
我可以想象它会很慢,你的for循环是在10列中单独输入741次迭代的单元格值,所以大约有7.4k个单元格条目单独完成。
您可以在数组中创建单元格值,然后将该数组粘贴到工作簿中,或者更简单地在顶行输入预期的公式并根据需要进行填充。
作为示例,您可以替换:
For i = 0 To 740
Loktider.Range("C4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C6"
Loktider.Range("D4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C5"
Loktider.Range("E4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C16"
Loktider.Range("F4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!R" & CStr(11 + i) & "C15"
Loktider.Range("G4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C6"
Loktider.Range("H4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C5"
Loktider.Range("I4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C16"
Loktider.Range("J4").Offset(i, 0) = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!R" & CStr(11 + i) & "C15"
Next
使用:
编辑 - R1C1参考系统似乎使用绝对值,而不是添加标准单元格参考
with Loktider
.Range("C4") = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!F11"
.Range("D4") = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!E11"
.Range("E4") = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!P11"
.Range("F4") = "='[Simulering Arbeidsplan Ovn 3 28h.xls]Lokklegging'!O11"
.Range("G4") = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!F11"
.Range("H4") = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!E11"
.Range("I4") = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!P11"
.Range("J4") = "='[Simulering Arbeidsplan Ovn 4 30h.xls]Lokklegging'!O11"
Range(.Cells(4,3),.Cells(744,10)).FillDown
End With
这是一些假设,Loktider
是您创建的worksheet
变量,并且当您对循环计数器进行硬编码时,您将使用该特定范围。