Need to eliminate green triage for "Formula omits adjacent cells"

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
275
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
Platform
  1. Windows
  2. MacOS
I have a workbook that creates another workbook, and copies one of the sheets to it, via VBA code. Let's call this sheet "NewSheet". I place some formulas in NewSheet in a few cells. In those cells, I see the little green triangles in the top left corner, with the error "Formula omits adjacent cells". With VBA code, I would like to make the little green triangles go away.

I did some research on this board, and found a thread that I thought would help solve it.
Ignor Error: Inconsistent Calculated Column Formula using VBA

It doesn't look like it's for the same exact error, but I figured the code itself would work, and I could just change the number next to "Errors" until it worked. However, I couldn't get it to work no matter what I tried.

VBA Code:
        Dim cel As Range
        Dim r As Range
        Set r = ThisWorkbook.Sheets("NewSheet").Range("AF9:AF" & LastRow)
        
        For Each cel In r
            cel.Errors(1).Ignore = True
            cel.Errors(2).Ignore = True
            cel.Errors(3).Ignore = True
            cel.Errors(4).Ignore = True
            cel.Errors(5).Ignore = True
            cel.Errors(6).Ignore = True
            cel.Errors(7).Ignore = True
            cel.Errors(8).Ignore = True
            cel.Errors(9).Ignore = True
        Next cel
        
        Set r = Nothing
        Set cel = Nothing

Note: LastRow is a variable because the last row that is affected will be different, depending on how much data is present on this sheet. In my testing, it is equal to 20.

I wasn't sure which number I needed to put in parentheses next to Errors, so that's why I tried all 9. The above code didn't work, so either the error I'm trying to ignore uses a different number, or something is wrong with the code itself. The code doesn't generate an error, but it also doesn't hide the little green triangle.

I'm on Windows 10 with Excel 365.

Any help would be appreciated!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try...
VBA Code:
.Errors(xlOmittedCells).Ignore = True
Edit:
It works for me with 365/W10 so if not for you then we have to look elsewhere (btw error number 5 works for me also)
 
Last edited:
Upvote 0
ThisWorkbook refers to the workbook containing the code, so if your workbook is creating a new workbook, your code appears to be looking at the wrong workbook.
 
Upvote 0
Thanks MARK858 and RoryA!

Sorry, my initial post wasn't 100% clear. Before I posted it, I ended up moving the code that tries to ignore the error to BEFORE the sheet is copied, because I thought the act of copying it might make a difference. Well, it turns out it did, but in the opposite direction. I tried the code that MARK858 suggested, and it worked, but only on the sheet within ThisWorkbook. Once that sheet was copied to the new workbook, the green triangles were there again. So, I moved the code back to later in the sub, so it happened AFTER the sheet was copied to the new workbook. That time, it all worked as it should have. So, problem solved. Thanks to you both!
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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