2015-01-26 2 views
1

다음 코드에서는 수식 결과를 셀에 추가 할 수 있지만 셀의 수식이 필요하므로 범위 값을 변경할 때 매크로가 실행되면 해당 셀의 값이 업데이트됩니다.범위를 참조하는 Excel 셀에 수식 추가

아래 코드는 문제가있는 행입니다.

세포 (I, LastCol) .Value = Application.WorksheetFunction.SumIf (Sourcerange "< ="& 세포 (2, 2), FillRange)

Set Sourcerange = Range("G3", Cells(3, LastCol)) 
    Range("G65536").End(xlUp).Select 
    Set wf = Application.WorksheetFunction 
    Set r = ActiveCell.Offset(0, LastCol) 
    r.Select 
    Set r = ActiveCell.Offset(0, -5) 
    r.Select 
    Set rAbove = Range(r, Cells(2, r.Column)) 
    RowCount = Range(r, Cells(2, r.Column)).Count 
    LastCol = r.Column 
    FillRange.Select 
    For i = 6 To RowCount + 1 
     Set FillRange = Range(Cells(i, 7), Cells(i, LastCol)) 
     FillRange.Select 
     Cells(i, LastCol).Value = Application.WorksheetFunction.SumIf(Sourcerange, "<=" & Cells(2, 2), FillRange) 
    Next i 

감사합니다 브랜든

+0

매크로 셀의 결과 정적 값을두고 시도, 바실리 방법은 셀에 수식을 넣습니다. 합계 범위 또는 조건 범위를 업데이트 할 때마다 Excel에서 계산할 때 셀의 값을 동적으로 업데이트합니다. – Larry

답변

2

Cells(i, LastCol).Formula = "=SUMIF(" & SourceRange.Address & ",""<=""&" & Cells(2, 2).Address & "," & FillRange.Address & ")" 
+0

니스! ... 완벽하게 작동했습니다. 감사! – brandon