Help With Macro

meppwc

Well-known Member
Joined
May 16, 2003
Messages
604
Office Version
  1. 365
Platform
  1. Windows
The macro at the bottom of this message performs a lookup based on the value in column N. It correctly populates columns P and Q with an ID and person's name.
If data does not exist in column N, then the macro is returning #N/A
Is there anyway to modify this macro so that if data is not present in column N, then P and Q are also blank opposed to the #N/A ?



Sub populatePOCsNameID()
'
'
'
Sheets("Summary").Select
Range("P4").Select
ActiveCell.FormulaR1C1 = _
"=LOOKUP(RC[-1],'Lookup Tables'!R1C1:R27C1,'Lookup Tables'!R1C2:R27C2)"
Range("Q4").Select
ActiveCell.FormulaR1C1 = _
"=LOOKUP(RC[-2],'Lookup Tables'!R1C1:R27C1,'Lookup Tables'!R1C3:R27C3)"
Range("P4:Q4").Select
Selection.AutoFill Destination:=Range("P4:Q30"), Type:=xlFillDefault
Range("P4:Q30").Select
Range("R3").Select
End Sub
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
oldbrewer.........I understand the logic.............but in a macro, I don't know where and how to place this exception............needing syntax
 
Upvote 0
Don't have Excel at the moment, but try..
Code:
Sub populatePOCsNameID()
Sheets("Summary").Range("P4:P30").Formula = _
"=IF(ISERROR(LOOKUP(P3,'Lookup Tables'!A1:A27,'Lookup Tables'!B1:B27)),"""",LOOKUP(P3,'Lookup Tables'!A1:A27,'Lookup Tables'!B1:B27))"
Range("Q4:Q30").Formula = "=IF(ISERROR(LOOKUP(O4,'Lookup Tables'!A1:A27,'Lookup Tables'!C1:C27)),"""",LOOKUP(O4,'Lookup Tables'!A1:A27,'Lookup Tables'!C1:C27))"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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