Application-defined or object-defined error with FormulaR1C1 - vba

I've got some code that isn't working, and have basically simplified it as much as possible for the sake of this post. I'm trying to run this macro and get an error saying
Application-defined or object-defined error
Am I missing something obvious?
Sub Test()
Range("B1").FormulaR1C1 = _
"=VLOOKUP(RC[-1],R2C6:R4C7,2,FALSE),0))"
End Sub
Thanks!

Your VLOOKUP has an extra parameter hanging off the right side.
Sub Test()
Range("B1").FormulaR1C1 = _
"=VLOOKUP(RC[-1], R2C6:R4C7, 2, FALSE)"
End Sub

Related

VBA Vlookup using ActiveCell as reference [duplicate]

This question already has answers here:
How to error handle 1004 Error with WorksheetFunction.VLookup?
(3 answers)
Closed 4 years ago.
I am trying to develop a form to track invoices as they come in. The form will have a combobox where I can click on and select a vendor number. I want the textbox to automatically fill in based on the vendor number selected from the combobox. Here's what I have so far:
Private Sub ComboBox1_Change()
'Vlookup when ComboBox1 is filled
Me.TextBox1.Value = Application.WorksheetFunction.VLookup( _
Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
End Sub
Worksheet 3 is from which the information is being drawn (the vendor number and name).
When I go back to the form to test the code, I get the following error:
Run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class
How do I fix this?
Try below code
I will recommend to use error handler while using vlookup because error might occur when the lookup_value is not found.
Private Sub ComboBox1_Change()
On Error Resume Next
Ret = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
On Error GoTo 0
If Ret <> "" Then MsgBox Ret
End Sub
OR
On Error Resume Next
Result = Application.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
If Result = "Error 2042" Then
'nothing found
ElseIf cell <> Result Then
MsgBox cell.Value
End If
On Error GoTo 0
I was having the same problem. It seems that passing Me.ComboBox1.Value as an argument for the Vlookup function is causing the issue. What I did was assign this value to a double and then put it into the Vlookup function.
Dim x As Double
x = Me.ComboBox1.Value
Me.TextBox1.Value = Application.WorksheetFunction.VLookup(x, Worksheets("Sheet3").Range("Names"), 2, False)
Or, for a shorter method, you can just convert the type within the Vlookup function using Cdbl(<Value>).
So it would end up being
Me.TextBox1.Value = Application.WorksheetFunction.VLookup(Cdbl(Me.ComboBox1.Value), Worksheets("Sheet3").Range("Names"), 2, False)
Strange as it may sound, it works for me.
Hope this helps.
I was just having this issue with my own program. I turned out that the value I was searching for was not in my reference table. I fixed my reference table, and then the error went away.

How to use IsText with VBA

I am learning VBA and am trying to execute the code:
Sub example()
If IsText(ActiveCell) Then
MsgBox "Is Text"
Else: MsgBox "Not Text"
End If
End Sub
It does not work, and gives me the error, "Compile Error: Sub or Function not defined" with the "IsText" highlighted. The macro works fine if I exchange "IsText" for "IsNumeric". Thanks for the help.
IsText is a worksheet function. Use worksheetfunction to apply it within vba.
If worksheetfunction.IsText(ActiveCell) Then

Having Run-time-error 1004 Application defined or object defined error

I have a simple formula in vba, like this :
Sub button_fu()
Windows("H1.xlsm").Activate
Sheets("jan").Activate
Range("J3").Select
Range("J3").Formula = "=IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,8,False))=1,""terhubung"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,9,False))=1,""unreach"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,10,False))=1,""reject"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,11,False))=1,""workload"","""")"
End Sub
anyone hepl me, how the problem solved it?
You are missing some closing brackets in your formula:
Sub button_fu()
Windows("H1.xlsm").Activate
Sheets("jan").Activate
Range("J3").Select
Range("J3").Formula = "=IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,8,False))=1,""terhubung"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,9,False))=1,""unreach"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,10,False))=1,""reject"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,11,False))=1,""workload"",""""))))"
End Sub
P.S. Should "FOLLOW UP H1.xlsx" be "H1.xlsm", or do you have another workbook?

Excel - VBA - formula error 1004 -

I'm getting an run-time error '1004' application-defined or object-defined error when I'm using the following vba code:
Private Sub CommandButton1_Click()
Dim formul as String
'Run Tercih14
formul = "=vlookup($c$15;'Şube Listesi'!$B:$J;9;FALSE)"
Sheet35.Range("F12").Formula = formul
End Sub
I can change the value of the F12 cell.assign different formulas like =sum(A1:A2) etc. If I create a new sheet and edit the code for the new sheet it works fine with the vlookup formula.
I checked, the sheet is not protected . I'm having trouble figuring out what the problem is here. Hope you guys can help me find the solution.
Change
"=vlookup($c$15;'Şube Listesi'!$B:$J;9;FALSE)"
to
"=vlookup($c$15,'Şube Listesi'!$B:$J,9,FALSE)"
You are using ;'s instead of ,'s
I had the same kind of issue with a formula containing variable
Dim Instruc As String
Instruc = "=MAX(R" & CStr(suiv) & ";S" & CStr(suiv) & " )"
MAIN.Cells(suiv, 20).Formula = CStr(Instruc)
When I use the ; caracter in the formula, I always get the run-time error '1004' application-defined or object-defined error
I used a variant of the formula with the : caracter
Dim Instruc As String
Instruc = "=MAX(R" & CStr(suiv) & ";S" & CStr(suiv) & " )"
MAIN.Cells(suiv, 20).Formula = CStr(Instruc)

"Unable to get the VLookup property of the WorksheetFunction Class" error [duplicate]

This question already has answers here:
How to error handle 1004 Error with WorksheetFunction.VLookup?
(3 answers)
Closed 4 years ago.
I am trying to develop a form to track invoices as they come in. The form will have a combobox where I can click on and select a vendor number. I want the textbox to automatically fill in based on the vendor number selected from the combobox. Here's what I have so far:
Private Sub ComboBox1_Change()
'Vlookup when ComboBox1 is filled
Me.TextBox1.Value = Application.WorksheetFunction.VLookup( _
Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
End Sub
Worksheet 3 is from which the information is being drawn (the vendor number and name).
When I go back to the form to test the code, I get the following error:
Run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class
How do I fix this?
Try below code
I will recommend to use error handler while using vlookup because error might occur when the lookup_value is not found.
Private Sub ComboBox1_Change()
On Error Resume Next
Ret = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
On Error GoTo 0
If Ret <> "" Then MsgBox Ret
End Sub
OR
On Error Resume Next
Result = Application.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
If Result = "Error 2042" Then
'nothing found
ElseIf cell <> Result Then
MsgBox cell.Value
End If
On Error GoTo 0
I was having the same problem. It seems that passing Me.ComboBox1.Value as an argument for the Vlookup function is causing the issue. What I did was assign this value to a double and then put it into the Vlookup function.
Dim x As Double
x = Me.ComboBox1.Value
Me.TextBox1.Value = Application.WorksheetFunction.VLookup(x, Worksheets("Sheet3").Range("Names"), 2, False)
Or, for a shorter method, you can just convert the type within the Vlookup function using Cdbl(<Value>).
So it would end up being
Me.TextBox1.Value = Application.WorksheetFunction.VLookup(Cdbl(Me.ComboBox1.Value), Worksheets("Sheet3").Range("Names"), 2, False)
Strange as it may sound, it works for me.
Hope this helps.
I was just having this issue with my own program. I turned out that the value I was searching for was not in my reference table. I fixed my reference table, and then the error went away.