Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA automatically changing .Range to .range

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.

like image 696
Siegfried BIC Avatar asked Dec 11 '14 14:12

Siegfried BIC


3 Answers

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

like image 127
kaybee99 Avatar answered Oct 16 '22 23:10

kaybee99


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

like image 45
Shari P Avatar answered Oct 17 '22 00:10

Shari P


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".

like image 7
Chrismas007 Avatar answered Oct 17 '22 00:10

Chrismas007