14

I have been writing an Excel macro to help me process data at work, and now that I have finished writing the code I keep getting errors because Microsoft Visual Basic keeps changing .Range to .range. Whenever it does this I get a compile error because the method doesn't exist.

Is there anyway to fix this? Is there a way to get around using .Range if there isn't? As long as my code keeps getting changed from .Range to .range it will keep spitting out errors here.

SOLVED: the error wasn't rooted in the method but the data member that preceded it.

4
  • 2
    The fact that .range appears in lower case should not cause compile errors. You would only get a 438 error if you are referring to the .Range property of an object that doesn't support it. (VBA methods and properties are not case sensitive)
    – Rory
    Dec 11, 2014 at 15:00
  • click on the culprit ".range" and press Shift+F2. This should take you to the definition of lowercase "range"
    – iDevlop
    Dec 11, 2014 at 16:13
  • 1
    Are you using Option Explicit ?
    – iDevlop
    Dec 11, 2014 at 16:14
  • I rolled back the edit as the OP should be the one to remove the "Solved" statement and add as his own answer. Dec 11, 2014 at 16:39

4 Answers 4

35

Try declaring Range as a Range somewhere in your code (note the case):

Dim Range As Range

then delete the statement.

This should convert all your range to Range

2
  • I've just cleared the same problem by this method. Thanks a lot!
    – Kimpro
    Nov 15, 2020 at 14:48
  • 2
    Brilliant answer. Ridiculous problem. What was Microsoft thinking?!
    – DavidHyogo
    Mar 1, 2022 at 13:57
7

EDIT: The O.P. stated:

SOLVED: the error wasn't rooted in the method but the data member that preceded it.

However, the related issues of a lowercase method can come from creating a variable or routine which you named range and the system will auto change case based on that definition. You should never create a variable or routine with the same name as a defined process like Range(). As mentioned by @RubberDuck:

This is a side effect of VB being case insensitive and the IDE trying to be "helpful".

3
  • 2
    I would just add that this is a side effect of VB being case insensitive and the IDE trying to be "helpful".
    – RubberDuck
    Dec 11, 2014 at 15:00
  • 2
    I just checked. I currently have nothing named range. I did have a variable named ranger earlier, but it has since been deleted. Dec 11, 2014 at 15:07
  • I've noticed that despite removing the lowercase range variable, vba will continue converting to the lowercase range until you reopen. Oct 27, 2015 at 16:00
1

I have several models and procedures, and at some point all of my Ranges got converted to lowercase range. My easy fix was to go to ThisWorkbook in my project, and Dim Range as Range there, and then it will automatically change "range" to "Range" everywhere it appears in your code

0

When you have use many times words like 'range', autocorrect will change 'Range' value to 'range'. Try manually change this method to 'Range' and sure that you don't have any variables like 'range'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.