I have been learning VBA over the last two months while trying to re-write a macro that my predecessor did not have time to finish/work out the bugs before he took another job. This forum has been amazing, but I have come to something that I can't find a fix for and I am hoping someone can help me out. I have included my sample data below.
I need to populate the column 'Ticket Owner" in worksheet "Data" based off of values in "Data" and two other worksheets ("Director" and "Market"). Everything stems from what is in Worksheet "Data" Column B (Queue).
My predecessor was attempting to accomplish this with this IF and ISERROR function:
********ActiveCell.FormulaR1C1 = "=IF(AND(ISERROR(VLOOKUP(RC[-10],'Director to Queue'!R2C1:R250C2,2,FALSE)),RIGHT(RC[-10],2)=""RN""),VLOOKUP(RC[-7],'Market to Director'!R2C1:R500C2,2,FALSE),VLOOKUP(RC[-10],'Director to Queue'!R2C1:R250C2,2,FALSE))"
I'll be honest I don't understand all of the components of his code, but one problem that keeps popping up is that if there is a new city name or queue name in the Data worksheet that has not been added to the other two worksheets the macro crashes.
I hope this makes sense. Thanks for any help that you can give me.
Excel 2010
<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Ticket Owner[/TD]
[TD="align: center"]Queue[/TD]
[TD="align: center"]Wrls_Mkt[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: center"]16[/TD]
[TD="align: right"][/TD]
[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: center"]18[/TD]
[TD="align: right"][/TD]
[TD="align: center"]19[/TD]
[TD="align: right"][/TD]
[TD="align: center"]20[/TD]
[TD="align: right"][/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: center"]22[/TD]
[TD="align: right"][/TD]
[TD="align: center"]23[/TD]
[TD="align: right"][/TD]
[TD="align: center"]24[/TD]
[TD="align: right"][/TD]
[TD="align: center"]25[/TD]
[TD="align: right"][/TD]
</tbody>
Excel 2010
<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Market[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]22[/TD]
</tbody>
Excel 2010
<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Queue[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]Group[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]10[/TD]
</tbody>
I need to populate the column 'Ticket Owner" in worksheet "Data" based off of values in "Data" and two other worksheets ("Director" and "Market"). Everything stems from what is in Worksheet "Data" Column B (Queue).
- If the value in Worksheet "Data" Column B (Queue) ends with "RN" then use the value in Column C (Wrls_Mkt) to lookup the name of the Director in Worksheet "Market" and paste that name into "Ticket Owner" in worksheet "Data".
- If the value in Worksheet "Data" Column B (Queue) DOES NOT end with "RN" then use the value in Column B (Queue) to look up the name in column B (Director) in Worksheet "Director" and paste that name into "Ticket Owner" in worksheet "Data".
- If either lookup fails to find a matching value then populate Column A of worksheet "Data" with "UNKNOWN"
My predecessor was attempting to accomplish this with this IF and ISERROR function:
********ActiveCell.FormulaR1C1 = "=IF(AND(ISERROR(VLOOKUP(RC[-10],'Director to Queue'!R2C1:R250C2,2,FALSE)),RIGHT(RC[-10],2)=""RN""),VLOOKUP(RC[-7],'Market to Director'!R2C1:R500C2,2,FALSE),VLOOKUP(RC[-10],'Director to Queue'!R2C1:R250C2,2,FALSE))"
I'll be honest I don't understand all of the components of his code, but one problem that keeps popping up is that if there is a new city name or queue name in the Data worksheet that has not been added to the other two worksheets the macro crashes.
I hope this makes sense. Thanks for any help that you can give me.
Excel 2010
A | B | C | |
---|---|---|---|
FOTORN | Toledo : Toledo | ||
V1ERRN | Miami / West Palm : Miami | ||
V1ALRN | Washington DC : Washington DC | ||
V1SARN | Miami / West Palm : Non-MSA | ||
V1SARN | DFW : Fort Worth / Arlington | ||
FOTORN | DFW : Fort Worth / Arlington | ||
V1AL | West Washington : Seattle / Bellevue / Everett | ||
FOTORN | Pittsburgh : Sharon | ||
V1ERRN | Tampa : Tampa / St. Petersburg / Clearwater | ||
V1ALRN | DFW : Fort Worth / Arlington | ||
V1SARN | Upper Central Valley : Modesto | ||
V1SARN | Upper Central Valley : Modesto | ||
FOTORN | Lower Central Valley : Bakersfield | ||
V1AL | West Texas : Non-MSA | ||
FOTORN | Myrtle Beach : Wilmington, NC | ||
V1ERRN | Myrtle Beach : Wilmington, NC | ||
V1ALRN | Memphis : Memphis | ||
V1SARN | Baltimore : Baltimore | ||
V1SARN | Chicago : Chicago | ||
FOTORN | North Wisconsin : Non-MSA | ||
V1AL | Myrtle Beach : Jacksonville, NC | ||
V1AL | New York City : New York | ||
FOTORN | West Texas : Non-MSA | ||
FOTORN | Ft. Wayne / South Bend : Fort Wayne |
<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Ticket Owner[/TD]
[TD="align: center"]Queue[/TD]
[TD="align: center"]Wrls_Mkt[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: center"]16[/TD]
[TD="align: right"][/TD]
[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: center"]18[/TD]
[TD="align: right"][/TD]
[TD="align: center"]19[/TD]
[TD="align: right"][/TD]
[TD="align: center"]20[/TD]
[TD="align: right"][/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: center"]22[/TD]
[TD="align: right"][/TD]
[TD="align: center"]23[/TD]
[TD="align: right"][/TD]
[TD="align: center"]24[/TD]
[TD="align: right"][/TD]
[TD="align: center"]25[/TD]
[TD="align: right"][/TD]
</tbody>
Data
Excel 2010
A | B | |
---|---|---|
Baltimore : Baltimore | Peter Pan | |
Baltimore : Non-MSA | Peter Pan | |
Boston : Barnstable / Yarmouth | Peter Pan | |
Boston : Boston | Peter Pan | |
Idaho : Boise City | Captain Hook | |
Inland Northwest : Non-MSA | Captain Hook | |
Inland Northwest : Richland / Kennewick / Pasco | Captain Hook | |
Inland Northwest : Spokane | Captain Hook | |
Cincinnati : Hamilton / Middletown | Tinker Bell | |
Cincinnati : Lima | Tinker Bell | |
Cincinnati : Non-MSA | Tinker Bell | |
Cleveland : Akron | Tinker Bell | |
West Kentucky : Non-MSA | Wendy Darling | |
West Kentucky : St. Louis | Wendy Darling | |
Alabama : Anniston | Wendy Darling | |
Alabama : Birmingham | Wendy Darling | |
Alabama : Decatur, AL | Wendy Darling | |
Arkansas : Fayetteville / Springdale / Rogers | Tiger Lily | |
Arkansas : Fort Smith | Tiger Lily | |
Arkansas : Little Rock / North Little Rock | Tiger Lily | |
Arkansas : Non-MSA | Tiger Lily |
<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Market[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]20[/TD]
[TD="align: center"]21[/TD]
[TD="align: center"]22[/TD]
</tbody>
Market
Excel 2010
A | B | C | |
---|---|---|---|
PROI | Mr. Smee | SACO | |
RSAN | George Scourie | OEM | |
ECPT | Black Gilmour | SACO | |
MOT2 | Canary Robb | SACO | |
T2LE | Bill Jukes | SACO | |
VBO2 | Black Pirate | SACO | |
VBSC | Alf Mason | SACO | |
WBHE | Robert Mullins | SACO | |
WBHSCB | George Scourie | SACO |
<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Queue[/TD]
[TD="align: center"]Director[/TD]
[TD="align: center"]Group[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]10[/TD]
</tbody>
Director