PDA

View Full Version : The code works, but the address is "WEIRD"



Factor3
03-03-2009, 11:16 AM
I'm trying to understand some output of some code, that WORKS fine.

I have a filled Range from "A1:G10" and I am using this code:

Dim TotalRange As Range

Range("A1").Select

Set TotalRange = Range(Selection.End(xlDown), Selection.End(xlToRight))
'THIS SELECTS THE CORRECT RANGE
TotalRange.Select
'THIS PRINTS OUT "$1:$1048576 => What the HECK IS THAT?"
Debug.Print (TotalRange.Address)

Again I am attempting to understand what the output of the Address is, because the code itself works fine:think:

Thanks incredibles!

Bob Phillips
03-03-2009, 11:27 AM
That sound to me like all cells in a 2007 worksheet, is it empty? Although when I tried it, I couldn't select it.

Factor3
03-03-2009, 12:23 PM
Hmmmm, that's strange. I have filled values in cells A1:G10. I start the code in cell A1, and when I step into TotalRange.Select, it selects cells A1:G10.

What do you mean you couldn't select it? you created a fillled range, started the code in the upper left region of the code and it didn't select the entire range?

Bob Phillips
03-03-2009, 12:32 PM
What I mean is that I cannot get the select to work and get the print that you get.

If I have a blank sheet, I get that print, but the TotalRange.Select fails.

If I have data, the TotalRange.Select worksbut I get a print of $A$1:$G$10.

Paul_Hossler
03-03-2009, 12:47 PM
Range("A1").Select


I think that this would use the Activesheet, and if it were empty, you would select all cells on the worksheet.

Maybe if you qualified the Range with Worksheets("name").Range ("A1") it would work

Paul

Factor3
03-03-2009, 01:11 PM
Oh SH*T, I think it must have to do with the fact that my Sub() is running from my PERSONAL.xlsx, instead of the actual workbook. But either way, I will qualify it using the ActiveSheet and Worksheets parent properties. I don't want to waste anyone else's time on this, thank you both tremendously!

mdmackillop
03-03-2009, 01:17 PM
Hi Factor3
What you get is the same range as selecting a cell, holding down Shift + Control, then pressing Down then Right arrows. It depends what is on your sheet what the result will be.