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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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,215,472
Messages
6,125,003
Members
449,203
Latest member
Daymo66

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