Thursday, March 24, 2005

#NUM Error when linking Excel Spreadsheet to Access Table

This happens because there is a combination of numbers and letters in one of the columns of the Excel file you want to link. This will always create a numeric field overflow error. Access uses the first 8 rows of the spreadsheet to determine the data type of the column in the linked table. Say for example that your first 8 rows in column A of your spreadsheet have the following data:
1
2
3
4
5
6
7
8
9A

If you link this dataset to an Access table, value 9A will produce a #NUM Error.


Here is some vba code that will fix this problem. The code will insert an apostrophe before the value in any cell that you have selected and in order to make the apostrophe invisible, the code will activate the next cell down the column. When the code is done running on the cells you have selected, the upper left hand corner of the cell will turn green. This means that Excel thinks that this cell has a value that is an error. Specifically, the error message says:
"The number in this cell is formatted as text or preceded by an apostrophe." Clicking on ignore error will do just fine. You can apply this “ignore error” fix to all the cells you have currently selected. If the green indicator doesn’t bother you, leave it alone, it’s harmless.

Let me know if the code helped you. Because I found some code in Microsoft’s website that was supposed to fix this problem but it didn’t. Their code deleted the first character of every cell I had selected.

Here’s my solution:
Select the cells that you want to fix and run this macro:

Sub ConvertToAlphanumeric()

Dim cell As Object

For Each cell In Selection
cell.Value = "'" & cell.Value
ActiveCell.Offset(1, 0).Activate
Next

MsgBox "done!"

End Sub

8 comments:

Anonymous said...

I have tried several recommended VB codes to fix this problem that just left my original data a mess or gone completely. This column with the formula returning the data as text worked wonderfully. The only catch was if the cell was blank then it still returned the #Num! error, I solved that by using either NA or 0 in those fields. And it works great. Thanks Bigwes99!!!!! :oD

Anonymous said...

Thanks for the code. It worked great. I have Excel Sheet that it is linked to Access Table, the Excel S. had dates in the cells, such as 01/02/07 but from time to time something gets voided and the user types in "Void" and the #Num error appeared.

Thanks Orlando.

Anonymous said...

I just changed the format of the whole worksheet to text as well as the field properties in the table on design view and it seemed to work.

Anonymous said...

I just have one file with 2 tabs.
This file has to link to a master table, but i need to leave define the column to run this macro everytime that i open the file for the specifics columns, thanks.

Anonymous said...

It worked great. Thank you.

Anonymous said...

Save worksheet as CSV/text file. There is an option to override default data type when linking CSVs in Access (which makes these linked table errors disappear).

Anonymous said...

Excellent Macro solution... It works.. thanks!!!

Anonymous said...

Thanks for the help...it works (sort of). I end up losing 2 characters off some off my individual cells (not all of them). Can the VB be changed to not do this?