次の式がありますRange("D3" , "D" & Total_Rows) = "=sum(A1:A10)"
D の前に列を挿入すると、この式は間違った列に配置されます。列 D に名前付き範囲を使用するように言われましたが、このタイプのコードでは、名前付き範囲を組み込む方法がわかりません。列を参照するために必要です。
1 に答える
0
あるインスタンスでは単一のセルを参照する必要があり、別のインスタンスでは列を参照する必要があるため、名前付き範囲を組み込む方法がわかりません。
の範囲プロパティを操作してみると、またはなどName
の通常の範囲メソッドを使用できます。.Resize
.Offset
Sub Test()
'Assume there is a named range in the worksheet
Dim nm As Name
Dim rngName As Range
Dim rngCell As Range
Dim rngColumn As Range
Set nm = ActiveSheet.Names(1)
Set rngName = Range(nm)
MsgBox "myName address: " & rngName.Address
Set rngCell = Range(nm).Resize(1, 1)
MsgBox "the first cell in myRange is " & rngCell.Address
Set rngCell = Range(nm).Resize(1, 1).Offset(3)
MsgBox "the third cell in myRange is " & rngCell.Address
Set rngColumn = Range(nm).EntireColumn
MsgBox "the column of myRange is " & rngColumn.Address
'Now insert a column in front of D
rngName.Insert
'Then view the addresses again, see that they have changed
Set rngName = Range(nm)
MsgBox "myName address: " & rngName.Address
Set rngCell = Range(nm).Resize(1, 1)
MsgBox "the first cell in myRange is " & rngCell.Address
Set rngCell = Range(nm).Resize(1, 1).Offset(3)
MsgBox "the third cell in myRange is " & rngCell.Address
Set rngColumn = Range(nm).EntireColumn
MsgBox "the column of myRange is " & rngColumn.Address
End Sub
于 2014-04-24T16:45:23.237 に答える