Macro runs differently from button vs. VBA (loop error)

Viewed 19

I'm trying to run some code that looks up a project number from one sheet and brings the related project manager from another sheet, and creates a column for it on the first sheet. Really just trying to consolidate the important data from both sheets so I can play with it in a pivot table elsewhere. When I assign the Macro to a button, it works, but only fills in data for the first instance, whereas when I run it using F5, it does the full loop and gets the data for everything. Very confused. Code below:

Sub Merge_and_calc()

N = Cells(Rows.Count, "A").End(xlUp).Row

Sheets("Export").Select

Range("AE1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Project Manager"
    
    With Range("AE2:AE" & N)
        .Formula = "=XLOOKUP(RC[-30],'Project Order Summary'!RC[-29]:R[998]C[-29],'Project Order Summary'!RC[-28]:R[998]C[-28], ""No Assigned PM"")"
        .Value = .Value
    End With

And yes, there's probably a sexier way to code this, but I'm fairly new. : (

0 Answers
Related