Macro not working when new parameter added

Hobbes25

New Member
Joined
May 16, 2018
Messages
8
So, I've been working on this for quite a while with no luck. All it's supposed to do is merge two files together. It works until I add a new parameter (location). I've tried several variations on the code with no luck. Do I have to add another VLOOKUP?

Code:
'Opening Source Files

    Workbooks.Open Filename:="xxx.csv"
    Workbooks.Open Filename:="xxxx.csv"

' Merging Files
    Workbooks("Mantas User Roles.xls").Sheets("Mantas_User_Roles").Copy After:=Workbooks("a-AMLxx-MantasGrp.csv").Sheets("a-AMLxx-MantasGrp")
    
    Workbooks("a-AMLxx-MantasGrp.csv").Sheets("a-AMLxx-MantasGrp").Activate
       
    Columns("C:C").Cut
    Columns("A:A").Insert Shift:=xlToRight
    Columns("B:B").Cut
    Columns("E:E").Insert Shift:=xlToRight
    LastRow = Sheets("a-AMLxx-MantasGrp").Cells(Rows.Count, 4).End(xlUp).Row
    lastrow2 = Sheets("Mantas_User_Roles").Cells(Rows.Count, 1).End(xlUp).Row
    Range("E2:E" & LastRow).Formula = "=VLOOKUP(C2,Mantas_User_Roles!$A$2:$E$" & lastrow2 & ",2,FALSE)"
    Range("F2:F" & LastRow).Formula = "=VLOOKUP(C2,Mantas_User_Roles!$A$2:$E$" & lastrow2 & ",3,FALSE)"
    Range("G2:G" & LastRow).Formula = "=VLOOKUP(C2,Mantas_User_Roles!$A$2:$E$" & lastrow2 & ",4,FALSE)"
    Range("H2:H" & LastRow).Formula = "=VLOOKUP(C2,Mantas_User_Roles!$A$2:$E$" & lastrow2 & ",5,FALSE)"
    Workbooks("a-AMLxx-MantasGrp.csv").Sheets("a-AMLxx-MantasGrp").Range("E2:H" & LastRow).Copy
    Workbooks("a-AMLxx-MantasGrp.csv").Sheets("a-AMLxx-MantasGrp").Range("I2:L" & LastRow).PasteSpecial xlPasteValues
    Workbooks("a-AMLxx-MantasGrp.csv").Sheets("a-AMLxx-MantasGrp").Columns("F:I").EntireColumn.Delete
    
    Range("A1").Formula = "Access Approver"
    Range("B1").Formula = "User Name"
    Range("C1").Formula = "User ID"
    Range("D1").Formula = "Cost Center"
    Range("E1").Formula = "Location"
    Range("F1").Formula = "Role 1"
    Range("G1").Formula = "Role 2"
    Range("H1").Formula = "Role 3"
    Range("I1").Formula = "Role 4"
    Range("J1").Formula = "Access Approved:"
    Range("K1").Formula = "SAR# of Request Submitted:"
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top