Not a script, but a database (mapping area codes to states) and a reference lookup formula. Instead of VLOOKUP, I prefer INDEX combined with MATCH.
First, you need to bring a database mapping the area codes to states into your Excel workbook. Assuming your data is in Sheet1, let’s put the database in Sheet2, starting in cell Sheet2!A1. You can find a current listing of the data at this webpage:
http://www.bennetyee.org/ucsd-pages/area.html
On that page, place your cursor at the start of the table (in front of the"A" in "Area Code in the first field of the table header, depress and hold the left mouse button, and drag the cursor down the page til you get to to final field in the table, just past the last “t” in “present”. Release the left mouse button, click the right mouse button, and select “Copy”. Go back into Excel, and in the worksheet Sheet2, cell A1, select “Paste/Paste Special/Text”. Notice that the first record (row 2) didn’t import cleaning, and just delete row 2. Add underline formatting to row 1 so Excel knows that that row is header information (not necessary, but best practice).
Now go back to Sheet1. Where you have your data in columns A and B, in column C, add this formula:
=INDEX(Sheet2!$A$1:$D$385,MATCH(VALUE(LEFT(B2,3)),Sheet2!$A$1:$A$385,0),2)
Copy it down as necessary. It will lookup the area code in the database and return the matching state.
If you would prefer to use VLOOKUP, you can use:
=VLOOKUP(VALUE(LEFT(B5,3)),Sheet2!$A$1:$D$385,2)
VLOOKUP is best when you need mathematical interpolations in your lookups, as it can return imprecise results. The INDEX function I provided will return an error it can’t find an exact match. To see what I mean, pick an invalid area code, like 222, and see the difference in what the two formulas return.
If you would like more precise geographic information that just state, you can change the last number in either formula from “2” to “4” (which changes the column number in the database from which the result is returned).
Good luck.