Named Range, Strange VBA thingy too

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
549
I have two Problems:

1. In my code, I search for ranges containing identifying text and label them (BodyStart and BodyEnd) like this.
Code:
Set BodyStart = Cells.Find(what:="General", searchorder:=xlByRows, searchformat:=False)

Then I try to name all of the cells between BodyStart and BodyEnd. I've selected the name BodyEntire. Like this...

Code:
Set BodyEntire = range(range("BodyStart"), range("BodyEnd"))

But with the above line of code, i always get the dreaded error 1004 - Method 'range' of object '_global' failed.

Am I naming the range incorrectly?

2. Also, shouldn't the " r " in range be automatically capitalized for all of this crap? I don't know why " r " is not capitalized, but that isn't disturbing the program, because it works everywhere else with the lower case...
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Joe

The reason for the error is because you are trying to use BodyStart as a named range. It isn't a named range, it's a range object.

Does this work?
Code:
Set BodyEntire = Range(BodyStart, BodyEnd)
 
Upvote 0
Thanks Norie...yeah, I shoulda seen it. It's just been a good long time since i've screwed with VBA. Got any ideas about why is giving me the lower case "r" in range???
 
Upvote 0
Joe

Do you have a variable called range?
 
Upvote 0
Actually, that's the first thing that I looked for...and I don't have one called "range". If i did, wouldn't it really screw up every code in every module for which the variable was operable???

Could it have something to do with my plugins? I loaded some utilities into my vba editor from this sight. That wouldn't do it would it?
 
Upvote 0
The only way I was able to simulate your problem was by declaring a variable called range.

Where is this happening? Is it every instance of range?
 
Upvote 0
Norie,

It appears that it happens for every occurence of "range" for every module in My Personal Workbook. However, upon looking at other excel workbooks that have their own isolated modules, I found that Range was capitalized. The plot thickens.
 
Upvote 0

Forum statistics

Threads
1,222,408
Messages
6,165,870
Members
451,989
Latest member
DannyBoy1977

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top