How to Fix VBA #NAME and ByRef Errors in 64-Bit Excel
Question details
The user is experiencing #NAME and ByRef argument type mismatch errors with a custom VBA function after migrating to 64-bit Excel.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Testing a custom VBA function that extracts cell comments in the Immediate window and using it within worksheet cells.
- Observed behavior
- The function returns a #NAME error in the worksheet, and testing it with a direct cell reference in the VBE Immediate window produces a 'ByRef argument type mismatch' error.
Ensure your VBA code is compatible with 64-bit environments (e.g., updating Declare statements with PtrSafe if API calls are used) and verify the syntax used to pass ranges in the Immediate window.
Use Proper Range Syntax in the VBE Immediate Window
Resolve the ByRef argument type mismatch by properly formatting cell references when testing functions in the Visual Basic Editor (VBE).
The 'ByRef argument type mismatch' error in the Immediate window often occurs because a raw cell reference like C14 is interpreted as an undeclared variable, not a Range object. To fix this, you must explicitly define it as a Range.
Press Alt + F11 to open the Visual Basic Editor (VBE) in Excel.
Press Ctrl + G to open the Immediate window at the bottom of the VBE.
Instead of typing '? GetComment(C14)', use the bracket evaluation shorthand by typing '? GetComment([C14])' and press Enter.
Alternatively, you can use the explicit Range object by typing '? GetComment(Range("C14"))' and press Enter.

Try WPS Office for Seamless VBA Compatibility
Avoid 32-bit to 64-bit migration headaches with WPS Office. WPS Spreadsheet offers excellent compatibility with Microsoft Excel macros, providing a lightweight, fast, and free alternative with a familiar user interface.
- 1. Download WPS Office: Visit the official WPS website to download and install WPS Office for free.
- 2. Open Your Macro File: Launch WPS Spreadsheet and open your existing .xlsm or .xls file.
- 3. Enable Macros: Click 'Enable Macros' in the security warning prompt to run your VBA functions seamlessly.

Frequently Asked Questions
Why do I get a #NAME error for my custom VBA function?
A #NAME error usually means the spreadsheet software cannot recognize the function name. This happens if macros are disabled, the function is spelled incorrectly, or the VBA module containing the function is not inserted as a standard module.
What does 'ByRef argument type mismatch' mean in VBA?
This error occurs when you pass a variable or value to a function that expects a different data type. In the case of cell references, passing an unquoted or unbracketed cell address in the Immediate window passes an Empty variant instead of the expected Range object.
Are macros from 32-bit Excel compatible with 64-bit versions?
Most standard VBA code works perfectly across both versions. However, if your code uses Windows API declarations, you must update them by adding the 'PtrSafe' keyword and changing pointers or handles to 'LongPtr' data types for 64-bit compatibility.




