If Range("AF1") = "#N/A" Then

jimmisavage

Board Regular
Joined
Jun 28, 2017
Messages
130
I have a simple VBA to hide and unhide cells based in a formula in AF1

Code:
If Range("AF1") = "Non Commercial" Then
        Columns("P").EntireColumn.Hidden = True
        Columns("Q").EntireColumn.Hidden = True
        Columns("R").EntireColumn.Hidden = True
    End If
If Range("AF1") = "Commercial" Then
        Columns("P").EntireColumn.Hidden = False
        Columns("Q").EntireColumn.Hidden = False
        Columns("R").EntireColumn.Hidden = False
    End If

This does the job but there is also an instance when AF1 can be #N/A which throws an error because i've not told it that would be an option.

I've tried adding an option of below but it doesn't seem to recognise the #N/A
Code:
If Range("AF1") = "#N/A" Then
        Columns("P").EntireColumn.Hidden = False
        Columns("Q").EntireColumn.Hidden = False
        Columns("R").EntireColumn.Hidden = False
     End If

How would I combat this?

Many thanks
Jimmi
 
IFERROR (not ISERROR)

The VBA code can be :

Range("AF1").Formula="=IFERROR(VLOOKUP(AE1,'Study Database'!B8:AN1001,9,0),""No Match"")"
 
Last edited:
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I spoke too soon! Now this only works if AF1 is #N/A. If it's not it won't move on to check if it's non-commercial or commercial :(

I don't see how that could be for the code in post #7 .
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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