Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88029

Populate VLOOKUP formula using VBA for all rows that have data in column A

$
0
0

I have a data set that includes scores for individuals, but the report lacks team manager assignments. I have a separate table that contains team manager assignments. The tricky part is that people change managers, and I have to keep the scores tied to the manager, and only new data would then be transferred to the new manager.

My thinking is that I have a query tab that I paste the data into. There is a column that always says "Item" for each record and isn't used for my purposes. So I thought if I made a control button that runs a VLOOKUP to pull the team manager assignment, within an If statement, for If the record contains "Item" in the specified column, then VLOOKUP runs and replaces the work "Item" with the Manager's Name. That way it would preserve the scores tied to the specific manager if someone changes managers.

THE PROBLEM: It seems that the macro runs for the first row correctly, however, it just repeats the same manager's name throughout the entire table where it says "Item". How can I make it pull the VLOOKUP data for each row and populate the correct team manager.

Code:

Sub AssignTeams()
    If Sheets("CallScrubQuery").Range("G2") = "Item" Then
        Range("G2:G"& Range("A"& Rows.Count).End(xlUp).Row).Formula = Application.WorksheetFunction.VLookup(Sheets("CallScrubQuery").Range("A2"), Sheets("TeamAssignment").Range("$A$2:$B$200"), 2, False)
    End If
End Sub

Viewing all articles
Browse latest Browse all 88029

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>