Pasting a formula into a dynamic table column

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
185
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am pasting a Vlookup formula into a table (information) that is dynamic. The formula goes fine, however I run code after that to replace #N/A with a 0. I have a line of code that finds the last row, however all my #N/A code does is find the last cell and place a 0 in it.


Code:
Sub VlookupFormula()
Dim lRow As Long
Dim ws As Worksheet
Range("P1").Select
ActiveCell.FormulaR1C1 = "Vlookup Amount"
Range("P2").Formula = "=VLOOKUP(O2,Table3[#All],4,FALSE)"
lRow = Cells(Rows.Count, 1).End(xlUp).Row
Set NARange = Worksheets("Data").Range("P2" & lRow)
Worksheets("Data").Activate
For Each CheckCell In NARange
    If Application.WorksheetFunction.IsNA(CheckCell) Then
         'CheckCell.Offset(0, 1).Copy
         Worksheets("Data").Range("Y1").Copy
         CheckCell.Select
         Worksheets("Data").Paste  'Doing this rather than value will bring formatting
    End If
Next CheckCell
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,223,990
Messages
6,175,817
Members
452,672
Latest member
missbanana

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