How to Fix ‘VBA Select Method Range Class Failed’ (Excel)

Written by Kasper Langmann

The Visual Basic for Applications (VBA) is a powerful tool that is used by Excel users to automate tasks. However, it’s not uncommon to encounter errors such as the ‘VBA Select Method Range Class Failed’. This error typically occurs when you’re trying to select a range that does not exist or is not visible. In this guide, we will explore the causes of this error and provide detailed steps on how to fix it.

Understanding the ‘VBA Select Method Range Class Failed’ Error

The ‘VBA Select Method Range Class Failed’ error is a runtime error that occurs when your VBA code attempts to select a range that does not exist or is not currently visible. This can happen for a variety of reasons, such as when a worksheet is hidden, when a range is outside the area of the current worksheet, or when the code is referencing a non-existent range.

Understanding the causes of this error is the first step towards resolving it. Once you know why the error is occurring, you can take the appropriate steps to fix it. In the following sections, we will delve deeper into the causes of this error and provide solutions for each cause.

Common Causes of the ‘VBA Select Method Range Class Failed’ Error

1. Hidden Worksheet

One of the most common causes of the ‘VBA Select Method Range Class Failed’ error is a hidden worksheet. If your VBA code is trying to select a range on a worksheet that is hidden, it will fail and throw this error. This is because the Select method cannot be used on a hidden worksheet.

To fix this error, you need to unhide the worksheet before running your VBA code. You can do this manually by right-clicking on the worksheet tab and selecting ‘Unhide’, or you can use VBA code to unhide the worksheet.

2. Non-Existent Range

Another common cause of this error is a non-existent range. If your VBA code is trying to select a range that does not exist, it will fail and throw this error. This can happen if you have deleted a range that your code is referencing, or if you have made a typo in your range reference.

To fix this error, you need to ensure that the range your code is referencing actually exists. You can do this by checking your range references and making sure they are correct. If you have deleted a range that your code is referencing, you will need to either recreate the range or modify your code to reference a different range.

3. Range Outside the Current Worksheet

The ‘VBA Select Method Range Class Failed’ error can also occur if your VBA code is trying to select a range that is outside the area of the current worksheet. This can happen if you have moved or resized your worksheet, causing the range your code is referencing to fall outside the visible area.

To fix this error, you need to ensure that the range your code is referencing is within the visible area of the current worksheet. You can do this by checking your range references and making sure they are within the visible area of the worksheet. If the range is outside the visible area, you will need to either move or resize your worksheet to bring the range back into the visible area.

How to Fix the ‘VBA Select Method Range Class Failed’ Error

1. Unhide the Worksheet

If the error is being caused by a hidden worksheet, the first step to fixing it is to unhide the worksheet. You can do this manually by right-clicking on the worksheet tab and selecting ‘Unhide’. If you have multiple hidden worksheets, you may need to repeat this process for each one.

Alternatively, you can use VBA code to unhide the worksheet. The following code will unhide all worksheets in your workbook:


Sub UnhideAllWorksheets()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Visible = xlSheetVisible
    Next ws
End Sub

2. Check Your Range References

If the error is being caused by a non-existent range or a range outside the current worksheet, the next step is to check your range references. Make sure that the range your code is referencing actually exists and is within the visible area of the current worksheet.

If you have deleted a range that your code is referencing, you will need to either recreate the range or modify your code to reference a different range. If the range is outside the visible area of the worksheet, you will need to either move or resize your worksheet to bring the range back into the visible area.

3. Modify Your VBA Code

If the error is still occurring after you have checked your range references and unhid your worksheets, the problem may be with your VBA code. You may need to modify your code to avoid using the Select method, which can often be the cause of this error.

Instead of using the Select method, you can directly reference the range you want to work with. For example, instead of using ‘Range(“A1”).Select’, you can use ‘Range(“A1”).Value’ to directly access the value of cell A1.

By understanding the causes of the ‘VBA Select Method Range Class Failed’ error and how to fix it, you can avoid this common pitfall and make your VBA code more robust and reliable. Remember, the key to resolving this error is to check your range references, unhide your worksheets, and modify your VBA code if necessary.