HLOOKUP returns #N/A, but the value is there

Alonshow

New Member
Joined
May 29, 2023
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Hi, I'm struggling with some formulas that use HLOOKUP to retrieve values from a table. I have checked that the reference values I give to HLOOKUP are correct, and that those values are present in the data table, but my formulas return #N/A even though everything seems to be correct.

Context: I believe this is an unusual case scenario for Excel. I have some mental health problems that heavily affect my day-to-day routine, and I use an Excel workbook to monitor my daily activity and assess whether I am making progress. The core of the workbook is a set of formulas that read data about my activity during the day and return a number that tells me how good/bad that day was. For instance, I want to follow about a dozen healthy daily habits every day (like eating vegs, taking my medication, doing some exercise, etc). One of the formulas counts how many of these I follow each day. If I run that formula for yesterday and the result is 11, that means that yesterday I was very consistent with my daily habits. If I get 5 it means there's room for improvement. And if I get 1 it means it was a disaster.

This particular formula looks like this:
=IF(ISNUMBER(Day_1), HLOOKUP(Day_1,Activities_2022B,19,FALSE), "")

This formula refers to the table Activities_2022B, which contains a list of my healthy habits for each day of the year. Row 19 of that table is a sum of the number of daily habits I have performed in a particular day.

These formulas have been working well for several years. However, one month ago I decided to do a bit of clean-up of the workbook because it had been growing so much that it was starting to be difficult to manage. As part of the clean-up, I used the Name manager to remove tables that didn't seem to be in use, and also to rename tables that are in use to make their names more consistent. At first, it seemed to work well, but the next time I tried to put the worksheet to actual use, lots of #N/A errors started to show up all over the place.

Now, when I try to rename the tables in the sheet, I get some weird error messages. For instance, if I try to rename the table Activities_2022B to Activities_2022 (without the B), Excel says that's not possible because there is another table called Activities_2022. However, that other table doesn't show up in the Name Manager or anywhere else.

I attach the range where my data is located, which is a part of the Activities_2022B table (the whole table is too big to post here).

Forum sample.xlsx
LYLZMAMBMCMDMEMFMGMHMIMJMKMLMMMNMOMPMQMRMSMTMUMVMWMXMYMZNANBNC
1Thu, 01-DecFri, 02-DecSat, 03-DecSun, 04-DecMon, 05-DecTue, 06-DecWed, 07-DecThu, 08-DecFri, 09-DecSat, 10-DecSun, 11-DecMon, 12-DecTue, 13-DecWed, 14-DecThu, 15-DecFri, 16-DecSat, 17-DecSun, 18-DecMon, 19-DecTue, 20-DecWed, 21-DecThu, 22-DecFri, 23-DecSat, 24-DecSun, 25-DecMon, 26-DecTue, 27-DecWed, 28-DecThu, 29-DecFri, 30-DecSat, 31-Dec
25 PM11 PM10 PM1 AM2 AM3 AM5 AM2 AM3 AM4 AM5 AM6 AM7 AM8 AM1 PM12 PM12 PM12 PM3 PM4 PM3 PM5 AM5 AM4 AM3 PM2 AM4 AM1 AM
34 PM4 PM5 PM6 PM10 PM8 PM4 PM5 PM8 PM10 PM11 PM10 PM10 PM6 AM5 AM3 AM3 AM7 AM11 AM7 AM12 AM11 PM11 PM5 AM3 PM7 PM5 PM3 PM
4876088591010877910770998585651001198
5xxxxxxxxxxxxxxxxxxx
6x
7xxxxxxxxxxxxxxxxx
8xxxxxxxxxxxxxxxxx
9xxxxxxxxxxxxxxxxxxxxxxxxxxx
10xx
11WalkingWalking
12
13
14xxxxxxxxxx
15MelanieMónicaMerceLang exchMerce
16MelanieJáledFundación AnarMerceLang exchMerce
18xxxxxxxxxxxxxxxxxxxxxxxx
1993415554922222835 255838355 555
21
22MónicaLang exch
23JáledMerceLang exchMerce
24
25xxxx
26MelanieMerceMerce
27
28Mónica
29-2  1    -2     -1      3 -100     
Routine tasks 2022
Cell Formulas
RangeFormula
LY4:NC4LY4=HOUR(IF(AND(ISNUMBER(LY2), ISNUMBER(LX3)), IF(LY2>LX3,LY2-LX3, (1+LY2)-LX3), IF(ISNUMBER(LY2),IF(LY2>LW3,LY2-LW3, (1+LY2)-LW3), 0)))
LY19:NC19LY19=IF(COUNTA(LY5:LY18)>0, COUNTA(LY5:LY18),"")
LY29:NC29LY29=IF(COUNTA(LY21:LY28)=0, "", 2*COUNTA(LY21) + 2*COUNTA(LY22) + COUNTA(LY23) - 2*COUNTA(LY26) - 3*COUNTA(LY27) - 4*COUNTA(LY28) + IF(COUNTA(LY24)=0, 0, 8-LY4))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B4:XFD4Cell Value=0textNO
C4:NC4Cell Valuebetween 11 and 500textNO


Thank you in advance for any help.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I guess your lookup row is 1, that is a "Date".
Assuming this is correct, what type of information is in "DAY_1"? Is it a Date (if you format that cell as Number with three decimals it should show as an Integer, example 44905.000) or a String (reformatting has no effect)?
 
Upvote 0
Yes, the lookup row is 1 and both Day_1 and the values in that row are dates (formatting them as numbers does show an Integer).
 
Upvote 0
On a free worksheet, insert in A1, A2, A3, A4 and A5 the following formulas:
Excel Formula:
=INDEX(Activities_2022B,1,0)

=ROWS(Activities_2022B)

=COLUMNS(Activities_2022B)

=ROW(INDEX(Activities_2022B,1,1))

=COLUMN(INDEX(Activities_2022B,1,1))
Then please show what you get (a screenshot of the first 10 columns should be sufficient)
 
Upvote 0
OK, I just copied and pasted your formulas in a new sheet in my workbook. Hope that's what you meant. This is the result:

1685389521574.png
 
Upvote 0
Ok
Those results demonstrated that the named range Activities_2022B starts from B2, and in row 1 times (not dates) are shown; I guess it should start B1.
So you need to go to Name Manager and adjust the "Refers to" area for that named range

Try...
 
Upvote 0
Yeah, I realized that's the problem just as I received your reply. Thank you. I feel a bit embarrassed that it was something so simple, but truth is, Excel's UI is a bit confusing in that sense. When the whole table is selected, visually it looks like the first row is a part of the selection, even though it is not. I guess that's what's kept me confused all this time.

The only thing now is that the name manager won't let me change the range of the table. When I select the table and click Edit, I get a dialogue that displays the range of the table greyed out and doesn't allow me to change it. Table design -> Resize table doesn't work either, it says the first row in the table must remain in the same row. Maybe I could just delete the table and create it again, but I wonder if that might create more problems than it solves... Any ideas?
 

Attachments

  • 1685389979637.png
    1685389979637.png
    10.6 KB · Views: 16
Upvote 0
So that range is indeed a "structured table" (ie an area declared as table, not only an ordered collection of rows and columns), and the dates are the headers of the table?
Probably the smart way would be using MATCH with the range Activities_2022B[#Headers] to determine the column and than INDEX.
But the easiest way should be using OFFSET in your original formula:
Excel Formula:
=IF(ISNUMBER(Day_1), HLOOKUP(Day_1,OFFSET(Activities_2022B,-1,0),19,FALSE), "")
Check if Index=19 is correct or need to be 20
 
Upvote 0
Solution
Please read the above message, but first check if this formula works:
=IF(ISNUMBER(Day_1), HLOOKUP(Day_1,Activities_2022B[#All],19,FALSE), "")
 
Upvote 0
the easiest way should be using OFFSET in your original formula:
=IF(ISNUMBER(Day_1), HLOOKUP(Day_1,OFFSET(Activities_2022B,-1,0),19,FALSE), "")
Worked! Thank you so much! So this solves the problem. The only thing is that this adds some complexity to the formula, so it would be even better if I could somehow redefine the table to include the dates/headers. But if that's not possible and/or too complicated, this is still a great solution :)

check if this formula works:
=IF(ISNUMBER(Day_1), HLOOKUP(Day_1,Activities_2022B[#All],19,FALSE), "")
For the record, this didn't work, returns #N/A.

So that range is indeed a "structured table" (ie an area declared as table, not only an ordered collection of rows and columns), and the dates are the headers of the table?
Also for the record, I don't understand this question. My knowledge of Excel is limited. Originally it was just a set of data, and at some point I decided to give it a name to make my formulas more manageable. I did think that the dates were the headers, but now that I've found out that the headers are not a part of the table, I'm not really sure. Here's a screenshot of the beginning of the table, in case it helps:
1685394809265.png
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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