VBA Type Mismatch Error (Error 13)

Boogerbut74

New Member
Joined
Oct 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I am very new to macros and VBA coding; right now, I'm having trouble with the code below. I'm trying to get it to do any row without changing the equation every time. So the C+ Active Cell.Row gets put in as an actual cell, same with F, then it's just looking at the q3 batch in these coulombs to find the exact match or next highest and gives me the data I want. Right now, though, I keep getting VBA Type Mismatch Error (Error 13), and I don't know how to fix it. I've been trying for a couple of hours now, and I'm just going down rabbit holes. I'm assuming my problem comes from quoting the C out and adding the ActiveCell.Row but I don't know how else to do this. I've put the line that's giving me problems bellow in red.








Sub Gmacro()
'
' Gmacro Macro
'

'
ActiveCell.Formula = "=XLOOKUP(C" + ActiveCell.Row + " & F" + ActiveCell.Row + ",'Q3 Batch Historian'!$A$1:A5045&'Q3 Batch Historian'!$C$1:C5045,ROW('Q3 Batch Historian'!$C$1:C5045), N/A,0,1)"


Range(ActiveCell).Select
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You usually don't add ( + ) strings - you concatenate them - &
I presume that range references need to be either bracketed [ ] or enclosed in quotes like "=XLOOKUP("C3", ) so literal quotes have to be doubled (or some expression allow the use single quotes, which makes it easier to write) like "=XLOOKUP('C'" & ActiveCell.Row & "'F'" & ActiveCell.Row ...
In these cases, sometimes the issue is that you need .Value when referring to a range, otherwise you can be passing the range address to the expression. That will certainly raise the error you're getting.

Suggest you get a formula to work in the sheet first then try concatenating references and variables in code. If you can't concatenate in code correctly, at least you could post a working formula.
 
Upvote 0
The problem is you need the ampersand not a plus. Also N/A will need to be ""N/A"" if you want N/A in the cell if not found. All that said you wont need a loop (which i presume you are intending to use) to add that formula to lots of cells. A loop would be slow.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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