VBA Nested IF and VLOOKUP

Machl22

New Member
Joined
Jun 16, 2018
Messages
11
Good Afternoon, All. I am attempting to use VBA to update "Area" values in Column A of my Weekly FFA tab based on a VLOOKUP of "District" values in Column B from the table in the "Districts" tab. The script must also fill down Column A based on the length of Column B. There are a few naming convention issues with some of the "District" names, and thus I am using a series of Nested IFs to align these Districts to their appropriate Districts. Unfortunately, I am running into Runtime Error 1004 Application -defined or object-defined error. Any assistance is greatly appreciated.

VBA Code:
With ThisWorkbook.Sheets("Weekly FFA")
    .Range("A6:A" & .Range("B" & .Rows.Count).End(xlUp).Row).Formula = "=IF(B6='COLO./WYOMING','WESTPAC',IF(B6='CONNECTICUT VALLEY PFC','ATLANTIC',IF(B6='GREATER BOSTON PFC','ATLANTIC',IF(B6='NORTHERN NEW ENGLAND PFC','ATLANTIC',IF(B6='PHILADELPHIA METRO','ATLANTIC',IF(B6='GREATER SC','SOUTHERN',(UPPER(VLOOKUP(B6,Districts!B:C,2,FALSE)))))))))"
End With
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Your values ned to be wrapped in double quotes like
VBA Code:
"=IF(B6=""COLO./WYOMING"",""WESTPAC"",IF(B6=""CONNECTICUT VALLEY PFC"",""ATLANTIC"","
 
Upvote 0
You can also write that formula like
VBA Code:
    .Range("A6:A" & .Range("B" & .Rows.Count).End(xlUp).Row).Formula = "=IF(B6=""COLO./WYOMING"",""WESTPAC"",IF(OR(B6={""CONNECTICUT VALLEY PFC"",""GREATER BOSTON PFC"",""NORTHERN NEW ENGLAND PFC"",""PHILADELPHIA METRO""}),""ATLANTIC"",IF(B6=""GREATER SC"",""SOUTHERN"",(UPPER(VLOOKUP(B6,Districts!B:C,2,FALSE))))))"
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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