Vlookup and #N/A

Kayslover

Board Regular
Joined
Sep 22, 2020
Messages
168
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have 12 workbooks called 01 Jan, 02 Feb, 03 Mar etc which are created from a template. (i.e. one for each month of the year).

Within the workbook I have individual sheets called Sheet1 thru to Sheet5 which hold weekly dates for the individual weeks in the month. Sheet1 always starts of being the first Sunday of month, sheet2 will be the next Sunday within that month etc.

I then have a sheet called “Monthly Totals” which by using the following array formula extracts details from Sheet1, Sheet2 etc. The formula is:-

VBA Code:
=VLOOKUP($A2,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A2)>0),0))&"'!$B$4:$V$10"),2,FALSE)
and it is present rows B2 to A32 in columns B to V.

Col A2 in Monthly Totals has a date starting as the first Sunday of the month, A3:A32 has the following formula:-

Code:
=IFERROR(IF(Formula!F$2-(A2+1)>=0, A2+1,""),"")
, where Formula!F$2 is the end of the month for the month in question.

The above formula will populate A2:A32 with just the date with the number of days in the month. Months like Feb and those that contain 30 days in the month, in Column A will only be populated with the exact number of days for the month

The problem I have, is as some months only have 30 days, the Vlookup reports #N/A for the 31st of those months and obviously February will report the 29th, 30th and 31st as #N/A.

In Row 33, I use the following formula:-

Code:
=SUMIF($A$2:$A$32,"<>",B2:B32)
to sum all the data for the month.

Is there any way to automate that for months with less than 31 days, the Vlookup in the appropriate rows for columns B to V either remove the formula or do not give #N/A? as it is hampering the formula
Code:
=SUMIF($A$2:$A$32,"<>",B2:B32)
to sum all the data for the month in row 33. People have to remember to remove the Vlookup in rows that do not have a date to get the totals in Row 33.

Thanks.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Sandy666,

Thank you for your quick response.

I have changed the Vlookup array formula in B31 and B32 to read
Rich (BB code):
=VLOOKUP($A31,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A31)>0),0))&"'!$B$4:$V$10"),2,FALSE),"")
=VLOOKUP($A32,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A32)>0),0))&"'!$B$4:$V$10"),2,FALSE),"")
and I now get #Name? in B31 and B32.

If I insert your recommeded formula in B33 (Total Line) as
Rich (BB code):
=IFNA(SUMIF($A$2:$A$32,"<>",B2:B32),"")
, B33 just goes blank.

As I doing something obviously wrong?
 
Upvote 0
Sandy666,

I have changed B31 and B32 to
Rich (BB code):
=IFNA(VLOOKUP($A31,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A31)>0),0))&"'!$B$4:$V$10"),2,FALSE),”0”)
=IFNA(VLOOKUP($A32,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A32)>0),0))&"'!$B$4:$V$10"),2,FALSE),”0”)

Please note that after the FALSE statement i have inserted a space character between the "".

Making the above change, now results in B31 and B32 displaying #NAME?.

I thought that by putting a space between the "" would result in formula to change to a space and deleting the formula?
 
Upvote 0
Sandy666,

Please ignore the last message, I had typed it incorrectly.

The message should have read:-

have changed B31 and B32 to

Rich (BB code):
=IFNA(VLOOKUP($A31,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A31)>0),0))&"'!$B$4:$V$10"),2,FALSE),”0”)
=IFNA(VLOOKUP($A32,INDIRECT("'"&INDEX(SheetList,MATCH(1,--(COUNTIF(INDIRECT("'"&SheetList&"'!$B$4:$V$10"),$A32)>0),0))&"'!$B$4:$V$10"),2,FALSE),”0”)

Making the above change, now results in B31 and B32 displaying #NAME?.

I thought that by putting a 0 (zero) between the "" would result in formula to be overwritten with a value of 0?
 
Upvote 0
so use IFERROR(formula, "") instead IFNA()

and instead of use "

 
Last edited:
Upvote 0
Solution
I have tried IFERROR and that also returns #Name?. Please note I an tying the IFERROR as part of the array formula.
 
Upvote 0
have you corrected your error according to the second line in post #7 ?
and did you read third line in the same post?
 
Upvote 0
Sandy666,

Apologies, I hadn't read post #7, and as you pointed out the error.

I have since corrected the formula (tried both the ISNA and IFERROR and both work) and bingo it works.

My sincere thanks for the assistance you have offered.
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,815
Members
448,990
Latest member
rohitsomani

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