我已经问过并提供了我自己的答案,虽然它不好但是有效。 Previous Question
但是,现在我想链接其他工作表中的单元格。但是,我写的程序无法在从一张纸到另一张纸的单元格中进行引用。
示例
Sheet1,A栏
Sheet2,第1行
我想要
Sheet1!A1 = Sheet2!A1
Sheet1!A2 = Sheet2!B2
答案 0 :(得分:1)
这是你在尝试的任何机会吗?
Option Explicit
Sub Sample()
Dim cRange As Range, rrange As Range
Dim i As Long, j As Long
Dim cPrompt As String, cTitle As String
Dim rPrompt As String, rTitle As String
On Error GoTo Whoa
cPrompt = "Please Choose a Column without Header"
cTitle = "Specify Column Range"
rPrompt = "Please Choose Starting cell"
rTitle = "Specify row Range"
Set cRange = Application.InputBox(cPrompt, cTitle, Type:=8)
Set rrange = Application.InputBox(rPrompt, rTitle, Type:=8)
For i = 1 To cRange.Count
rrange.Offset(j).Formula = "=" & cRange.Parent.Name & _
"!" & cRange.Cells(1, i).Address
j = j + 1
Next i
Exit Sub
Whoa:
MsgBox Err.Description
End Sub
答案 1 :(得分:0)
您可以通过使用INDIRECT函数以更简单的方式执行此操作,如下所示:
=INDIRECT("Sheet1!R1C"&ROW()+4,FALSE)
这使用当前行加上偏移值来将当前行与您要引用的第一列对齐。当您复制公式时,行号将增加,但将用于增加列引用。