2017-04-08 7 views
0

SUM 수식을 포함하는 열을 선택하려고합니다. 수식을 복사하고 같은 열의 값만 과거로 복사하려고합니다. 이 코드는 수식을 값으로 변경하지 않습니다. 어떻게 내가 이걸 해결할 수 있을지 생각해?vba의 지난 값

Sub Registrereren() 

Application.Calculation = xlCalculationManual 
Application.EnableEvents = False 
Application.ScreenUpdating = False 

On Error Resume Next 

Dim oWkSht As Worksheet 
Dim LastColumn As Long 
Dim c As Date 
Dim myCell As Range 
Dim LastRow As Long 

Sheets("Registration").Activate 


Set oWkSht = ThisWorkbook.Sheets("Registration") 
LastColumn = oWkSht.Range("A" & Columns.Count).End(xlToRight).Column 
LastRow = oWkSht.Range("C" & Rows.Count).End(xlUp).Row 

c = Date 

Set myCell = oWkSht.Range("1:1").Find(What:=c, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False, SearchOrder:=xlByColumns) 

If Not myCell Is Nothing Then 
    myCell.Offset(1, 0).Formula = "=New_Order!N2+New_Order!O2+New_Order!P2" 
    Range(myCell.Offset(1), Cells(LastRow, myCell.Column)).Select 
    Selection.FillDown 

    Range(myCell.Offset(1), LastRow).Select 
    Selection.Copy 
    Range(myCell.Offset(1), LastRow).PasteSpecial xlPasteValues 
End If 

Sheets("Main").Activate 

Application.Calculation = xlCalculationAutomatic 
Application.EnableEvents = True 
Application.ScreenUpdating = True 

End Sub 

답변

1

시도해보십시오. LastRow는 행 번호이므로 유효한 범위가 아닙니다.

Sub Registrereren() 

Application.Calculation = xlCalculationManual 
Application.EnableEvents = False 
Application.ScreenUpdating = False 

Dim oWkSht As Worksheet 
Dim LastColumn As Long 
Dim c As Date 
Dim myCell As Range 
Dim LastRow As Long 

Set oWkSht = ThisWorkbook.Sheets("Registration") 
LastColumn = oWkSht.Range("A" & Columns.Count).End(xlToRight).Column 
LastRow = oWkSht.Range("C" & Rows.Count).End(xlUp).Row 

c = Date 

Set myCell = oWkSht.Range("1:1").Find(What:=c, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False, SearchOrder:=xlByColumns) 

If Not myCell Is Nothing Then 
    With oWkSht.Range(myCell.Offset(1), oWkSht.Cells(LastRow, myCell.Column)) 
     .Formula = "=New_Order!N2+New_Order!O2+New_Order!P2" 
     .Value = .Value 
    End With 
End If 

Sheets("Main").Activate 

Application.Calculation = xlCalculationAutomatic 
Application.EnableEvents = True 
Application.ScreenUpdating = True 

End Sub 
+0

브릴리언트. 고맙습니다 –