VBA & Macro Problems

How to Fix VBA #NAME and ByRef Errors in 64-Bit Excel

Elise WilliamsElise Williams Oct 28, 2026 868 views

Question details

The user is experiencing #NAME and ByRef argument type mismatch errors with a custom VBA function after migrating to 64-bit Excel.

How to Fix VBA #NAME and ByRef Errors in 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Visual Basic Editor

Press Alt + F11 to open the Visual Basic Editor (VBE) in Excel.

2
Access the Immediate Window

Press Ctrl + G to open the Immediate window at the bottom of the VBE.

3
Use Bracket Evaluation

Instead of typing '? GetComment(C14)', use the bracket evaluation shorthand by typing '? GetComment([C14])' and press Enter.

4
Use Explicit Range Object

Alternatively, you can use the explicit Range object by typing '? GetComment(Range("C14"))' and press Enter.

Use Proper Range Syntax in the VBE Immediate Window
Worksheet Syntax: When using the function directly in a worksheet cell, the standard syntax '=GetComment(C14)' works perfectly fine as Excel automatically passes it as a Range object.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website to download and install WPS Office for free.
  2. 2. Open Your Macro File: Launch WPS Spreadsheet and open your existing .xlsm or .xls file.
  3. 3. Enable Macros: Click 'Enable Macros' in the security warning prompt to run your VBA functions seamlessly.
Highly compatible with Microsoft Excel (.xlsx, .xls, .xlsm) formats and macros.Free and lightweight, avoiding heavy system resource usage.Familiar tabbed UI ensures zero learning curve when switching from MS Office.Built-in VBA editor supports standard macro operations and custom functions.
microsoft office alternative - wps office

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.