I have some large data sets that I am automating and distributing. I want to eliminate the little green triangles that warn the user about numbers stored as text. I have used the following code but it's VERY slow on massive sheets.
Range(Cells(1, 1), Cells(lastrow, lColumn)).Select
'kill those dang green cell triagles
Dim rngCell As Range, bError As Byte
For Each rngCell In Selection.Cells
For bError = 3 To 3 Step 1
With rngCell
If .Errors(bError).Value Then
.Errors(bError).Ignore = True
End If
End With
Next bError
Next rngCell
As you can see I already cut it down to 1/7th of the time by not looping through every error just the one I am trying to prevent but it's still VERY slow.
Also I already know about
Application.ErrorCheckingOptions.NumberAsText = False
But I don't want to use it as I do not want to change users system settings. I want the effect of the loop without looping through all cells. Can I some how tell Excel to stop checking an entire range without looping cell by cell?
Any effective and fast way to do this would be very helpful. Thank you in advance!!
You can use workbook events to turn on and off the user's system setting, and restore the setting back to the original value when you're done.
In the ThisWorkbook object, put an Open event that takes note of their initial setting and then turns it off.
Add a BeforeClose event to set it back to original value when closing the file.
Then add Activate and Deactivate events so it switches when the user opens or views a different spreadsheet.
You could add similar events at the sheet level to turn it on and off when switching sheets within the workbook.
Would also be wise to add some error handling that sets it back to original value so you don't accidentally leave it in the wrong state in the unlikely event that your code bugs out somewhere.
I have created a nifty procedure to put the error in the 'ignore' list: Have fun
There appears to be an error in the code shared by the original poster. In order to get this to work I have add to add in the .Item of the error:
The preferred solution would be to convert the string to a number before you bring it into Excel. For example, when I am working with SQL and I have some numerical values stored as a
NVARCHAR
in the database I will use aCONVERT(int, colName)
in the SQL statement when I am bringing it into Excel. This brings it in as a number and I no longer get that message.Now, if this sort of option isn't available to you, you can fix that error another way. Simply set the range of values that have the number stored as text error equal to itself.
For example:
Where
A1:A3
in this example is the range of values you want to no longer store as text.Since your numbers have leading zeroes, you can change the formatting of these cells to add these zeroes as such:
This will change the display to show leading zeroes again. If you are exporting this data in any fashion you may have to take steps to ensure that this particular column is exported as text and not number, but I can't help much more without specifics.
The obvious answer (
Range(...).Errors(3).Ignore = True
) doesn't seem to work when the Range is larger than a single cell.After a bit of experimentation, I found that you can manually select the range of cells and click the little pop-up menu that appears and tell it to ignore all errors in the range, but this doesn't appear to have a VBA equivalent.
Doing this experiment with the macro recorder on records nothing, which is usually a sign that the programmer at Microsoft who implemented this functionality was incompetent.
Sadly, I think this means that there is no solution other than looping.
Related