Compile Error Invalid use of property

larrygreg

New Member
Joined
Dec 27, 2011
Messages
46
I am in th process of switching over from a worksheet to vba code.

I am stuck on one are with table lookups.

Code in the workbook is;

=IFERROR(IF(XXX="XXX",VLOOKUP(XXXX,'Directory[EXCEL FILE]SHEET'!$A:$E,5,0))

In my VBA Code, I have;

If Selection.Value = "XXXX" Then
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 "=IFERROR(VLOOKUP(R[0]C[-1], '[File]Sheet'!$A:$E,5,0"""")"
End If
I get a compile error of Invalid use of property.

Any suggestions.

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try

Code:
ActiveCell.FormulaR1C1 "=IFERROR(VLOOKUP(RC[-1], '[File]Sheet'!$A:$E,5,0,"""")"
 
Upvote 0
I think you'd need:

Code:
ActiveCell.FormulaR1C1 "=IFERROR(VLOOKUP(RC[-1], '[File]Sheet'!C1:C5,5,0),"""")"

But note that the '[File]Sheet' does need to be a valid file name and sheet name which I suspect they are not at the moment.
 
Upvote 0
Thanks for the replies. I changed the file name, so I have a local table that is named. However my problem still exists.

The error is occuring at formular1c1

Is there another way to get the value in the cell?

Thanks for the help
 
Upvote 0
You also need an = between FormulaR1C1 and the start of the string.

ie

Rich (BB code):
ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1], '[File]Sheet'!$A:$E,5,0,"""")"
Adjust [File]Sheet accordingly.
 
Upvote 0
I am getting a 'Compile error - Invalid use of property' while using the following macro trigger: -

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$Q$30" Then
If Target.Value > 1 Then
Sort
End If
End If
End Sub

Can anyone help me debug this?
 
Upvote 0
What is Sort? If it is a subroutine you should rename it as Sort is a VBA keyword.
 
Upvote 0
Try changing its name to MySort then use

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$Q$30" Then
    If Target.Value > 1 Then
        Call MySort
    End If
End If
End Sub
 
Upvote 0
Try changing its name to MySort then use

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$Q$30" Then
    If Target.Value > 1 Then
        Call MySort
    End If
End If
End Sub

The above changes stop the error to appear, however the code doesn't trigger the macro anymore. Can't understand why :( . Could you help if I could mail you the spreadsheet. Please reply. Thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,820
Members
449,409
Latest member
katiecolorado

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