Excel vba wont run formula

vbacoder12

New Member
Joined
Sep 4, 2024
Messages
41
Office Version
  1. 2024
  2. Prefer Not To Say
Platform
  1. Windows
Hi,
I am placing this code into vba hopefully when I try to run i am getting run time error 1004. Application defined or object defined error.

Sub insert formula and drag
Dim last row as long
Lastrow=Range("K" & Rows.Count).End(xlUp).Row
Range("k7").formula="=IfNa(vlookup(j7,Codes!A:B,2,False),"")"
Range("k7").auto fill destination:=Range("K7:K" & Lastrow)
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Not tested, but it looks like you need to double up the internal quotes:

Rich (BB code):
Range("k7").formula="=IfNa(vlookup(j7,Codes!A:B,2,False),"""")"
 
Upvote 0
Solution
@vbacoder12
A few points that might help you get better/faster answers for any future questions
  1. When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block at the bottom of this post has more details.

  2. Post your actual code (Copy/Paste) rather than re-type your code into your post. That should stop errors that might mislead your helpers. For example, in your code from post 1 your first line is
    Sub insert formula and drag
    That is not a valid code line (spaces not allowed in procedure name) so you with that code you would not have actually got the 1004 error you mentioned. Similarly your line ..
    Dim last row as long and Range("k7").auto fill destination:=Range("K7:K" & Lastrow)
    .. are not valid code lines (again spaces where they should not be).
    Such errors make it considerably harder for helpers to test and debug your code.

  3. When you do report a vba error with code, explain which line of the code gives the error.

  4. Your profile says "Prefer not to say" for your Excel version. Whilst that is a valid choice in the software, I'm wondering why choose it? Since different Excel versions have different features available to them, your forum helpers have no idea which features you have which you do not have. I can't see that there is anything at all sensitive about an Excel version so why not show what version(s) you actually have? You can edit that information by clicking your user name at the top right of the forum and choosing 'Account details'. (Don't forget to scroll to the bottom and click 'Save' if any changes are made.)
 
Upvote 0
You are right
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,225,619
Messages
6,186,045
Members
453,335
Latest member
sfd039

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