Resetting Lookup for formulas by copy and pasting VBA

时间:2016-04-04 18:13:11

标签: excel vba excel-vba foreach

Every Monday I have a report that I send out. On this report I paste data into the back and through a series of lookup functions (index/matches mostly) it pulls the data through to the correct fields. But, from week to week I will overwrite these lookup functions if the data wasn't correct or something may need to be added to the lookup.

Do remedy this I have a row of all the functions that I can copy and paste the function to if I hand-keyed over my function. I wrote the following VBA script that would do to this to all of my functions essentially "resetting" my report. The loop is working correctly but it won't paste correctly. It gives me error: "438 Object doesn't support this property or method."

'Reset the formulas to orignal lookup formulas
Public Sub Reset_Formulas2()
Dim DPNL2 As Worksheet
Dim r As Range, c As Range, reportRows As Range, reportColumns As Range

Set DPNL2 = ActiveWorkbook.Sheets("2016 Redesigned")

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

Set reportRows = DPNL2.Range("B8:B60")
Set reportColumns = DPNL2.Range("K:BL")

'Loop through columns
For Each c In reportColumns

    'Loop through rows
    For Each r In reportRows

        If r.Value > 0 Then
            DPNL2.Cells(7, c.Column).Copy
            r.Offset(0, c.Column - 2).Paste
            Application.CutCopyMode = False
        End If

    Next r

Next c

'Turn Settings back on
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic

End Sub

My next solution would be "dragging down" the "Master Lookups" and writing all of my summary functions again.

Would greatly apperciate and help on this!

0 个答案:

没有答案