In this tutorial we’ll learn how to fix this error by simple modifications in our VBA code. First, we will create this error and then remove it by making appropriate amendments in the code. To simulate this error, our dataset should have a named range. As shown above.
Microsoft Office provides support for programmers through its own programming language Visual Basic for Applications also known as VBA. We can use this programming language for automating our tasks in Microsoft Office Applications, i.e., Excel, Word, PowerPoint, Access etc. Getting errors while creating and running a software code is an inevitable fact. “method range of object _global failed” is a very common error while handling the named ranges in VBA.
Step 1 – Simulate the error by misspelling the name of the range
– To simulate the issue, we’ll intentionally use the wrong name “My_Sale” instead of the actual name of the Named Range which is “My_Sales”.
– This will simulate the error as shown above.
Step 2 – Rectify the error by using actual name of the range
– To rectify the issue, we’ll simply change the wrong name “My_Sale” to the actual Name of the Named Range which is “My_Sales”.
– This will solve the error and our goal of changing the interior color of the whole named range to yellow will be achieved without any problems, as shown above.