2014-04-24 2 views
0

다음과 같은 수식이 있습니다. Range("D3" , "D" & Total_Rows) = "=sum(A1:A10)" D 앞에 열을 삽입하면이 수식이 이제는 잘못된 열에 들어갑니다. 나는 D 열에 대해 명명 된 범위를 사용하라는 말을 들었지만이 코드 유형에서는 명명 된 범위를 통합 할 수있는 방법을 알지 못합니다. 한 인스턴스에서 단일 셀을 참조해야하고 다른 인스턴스에서는 열을 참조해야합니다.VBA 코드 및 명명 된 범위의 상대 범위

+0

같은 일반적인 범위의 방법을 사용할 수 있습니다 현재 좋아해? – Blackhawk

+0

아직 시도한 것이 있습니까? –

답변

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