Help With Macro

meppwc

Well-known Member
Joined
May 16, 2003
Messages
537
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

meppwc

Well-known Member
Joined
May 16, 2003
Messages
537
Office Version
  1. 365
Platform
  1. Windows
oldbrewer.........I understand the logic.............but in a macro, I don't know where and how to place this exception............needing syntax
 
Upvote 0

meppwc

Well-known Member
Joined
May 16, 2003
Messages
537
Office Version
  1. 365
Platform
  1. Windows
got it to work, thanks a bunch
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,600
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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,191,219
Messages
5,985,330
Members
439,958
Latest member
qb0000

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
Top