Trying to drag down vba formula - getting global error

Src016

New Member
Joined
May 21, 2019
Messages
10
Trying to run the following function to drag a formula I insert into a cell:

Dim LastRowMaster As Long

Sheets("Master").Select


numRows = Range("A1", Selection.End(xlDown)).Rows.Count
LastRowMaster = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row


Range("j2").Select
ActiveCell.Formula = "=IFNA(IF(VLOOKUP(E2,Responses!E:R,6,FALSE)=0,"""", (VLOOKUP(e2,Responses!E:R,6,FALSE))),"""")"
Range("j2").Select
Selection.AutoFill Destination:=Range("j2:j" & LastRowMaster)
'Range("J2").Select


Getting a run-time error 1004

Method 'range' of object'_Global'failed

Any ideas?

V/r,
Spencer
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You didn't tell us what line causes the error, but the formula doesn't have the correct syntax. Did you mean something like this?
Code:
ActiveCell.Formula = _
    "=IF(ISNA(VLOOKUP(E2,Responses!E:R,6,FALSE)),"""", VLOOKUP(e2,Responses!E:R,6,FALSE))"
 
Upvote 0
Src, did you place your code inside a Sub?

Public Sub DoThis()

'Code

End Sub
 
Upvote 0
I ran your code on Excel2010 just as you posted it. I had no issues.

Try it again but fully qualify the range [FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sheets("Master").Range("J2").Select

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Option Explicit
Sub test()
    Dim LastRowMaster As Long
    Dim numRows As Long
    Sheets("Master").Select
    
    numRows = Range("A1", Selection.End(xlDown)).Rows.Count
    LastRowMaster = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
    
    Sheets("Master").Range("j2").Select
    ActiveCell.Formula = "=IFNA(IF(VLOOKUP(E2,Responses!E:R,6,FALSE)=0,"""", (VLOOKUP(e2,Responses!E:R,6,FALSE))),"""")"
    Sheets("Master").Range("j2").Select
    Selection.AutoFill Destination:=Range("j2:j" & LastRowMaster)
    Sheets("Master").Range("J2").Select
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif][/FONT]


[/FONT]
 
Upvote 0
Thank you so much! That was the porblem exactly. I was stepping through the code, made the edits, and forgot to step through the part that fully qualifies the range Sheets("Master").Range("J2").Select

Thanks again.
 
Upvote 0
Thank you! This formula actually works significantly better paired with the code that drags it down. This forum is the best!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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