How can i write in vba the If(isna(vlookup(...) function?

Hernan_g_f

New Member
Joined
Jul 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I have three columns

A B C
1 1
2 4
3 7
4
5
6
7

I need to write in VBA at column B = If (isna(vlookup(Cells(i,"ColumnA").Value, Range(C1:C100),1,0)),""; vlookup(Cells(i,"ColumnA").Value, Range(C1:C100),1,0))

How can I do it? Thanks in advance!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How about
VBA Code:
 = If (isna(vlookup(Cells(i,1).Value, Range(C1:C100),1,0)),""""; vlookup(Cells(i,1).Value, Range(C1:C100),1,0))
 
Upvote 0
I wrote

For i = 27 To 37

s9.Cells(i, 16).Value = If (isna(vlookup(s9.Cells(i,3).Value, Range(BC16:BC4016),1,0));"""",1))

Next i

And appears a messange: Compile error Expected: expression and VBA mark "If"

How can I resolve it?
 
Upvote 0
That appears to be a different line of code than one originally posted.
It would be easier if you posted ALL of the code, not one line !
 
Upvote 0
Dim r1, r2 As Range
Set r1 = s9.Range("BC16:BC4016")
Set r2 = s9.Range("C27:C5027")
Set r3 = s9.Range("P27:P5027")

r2.Select
Selection.Style = "Comma"

x1 = WorksheetFunction.CountIf(r1, ">0")
x2 = WorksheetFunction.CountIf(r2, ">0")

For i = 27 To x2 + 27
s9.Cells(i, 16).Value = If (isna(vlookup(Cells(i,3).Value, Range(BC16:BC100),1,0)),""""; vlookup(Cells(i,3).Value, Range(BC16:BC100),1,0))
Next i

r3.Select
Selection.Copy
r3.Select
Selection.PasteSpecial xlValues
 
Upvote 0
It appears that you are trying to use a Worksheet Function in VBA without using the WorksheetFunction method.
 
Upvote 0
VBA Code:
Sub MM1()
Dim r1, r2 As Range
Set r1 = s9.Range("BC16:BC4016")
Set r2 = s9.Range("C27:C5027")
Set r3 = s9.Range("P27:P5027")

r2.Select
Selection.Style = "Comma"

x1 = WorksheetFunction.CountIf(r1, ">0")
x2 = WorksheetFunction.CountIf(r2, ">0")

For i = 27 To x2 + 27
Cells(i, 16).Value = WorksheetFunction.If(IsNA(VLookup(Cells(i, 3).Value, Range("BC16:BC100"), 1, 0)), """", VLookup(Cells(i, 3).Value, Range("BC16:BC100"), 1, 0))
Next i

With r3
.Value = .Value
End With
End Sub
 
Upvote 0
The trouble persist... :(
¿Could I send you the sheet with the macro by email? Thanks!

Dim r1, r2 As Range
Set r1 = s9.Range("BC16:BC4016")
Set r2 = s9.Range("C27:C5027")
Set r3 = s9.Range("P27:P5027")

r2.Select
Selection.Style = "Comma"

x1 = WorksheetFunction.CountIf(r1, ">0")
x2 = WorksheetFunction.CountIf(r2, ">0")

For i = 27 To x2 + 27
s9.Cells(i, 16).Value = WorksheetFunction.If(WorksheetFunction.IsNA(WorksheetFunction.VLookup(Cells(i, 3).Value, Range("BC16:BC40"), 1, 0)), """", 1)
Next i

With r3
.Value = .Value
End With
 
Upvote 0

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

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