ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable ranges (https://www.excelbanter.com/excel-programming/377447-variable-ranges.html)

igorek

Variable ranges
 
Hi,
As i write my code the range that i'm referring to changes. To identify the
lower and the upper limits of the range i use the following

BeginRange = Worksheets("Content").Cells(5, col).Address
EndRange = Worksheets("Content").Cells(Row, col).Address

Now, as i select this range and try to copy it elsewhere i'm trying to use
the following expression:

Worksheets("Content").Range("" & BeginRange & " :" & EndRange & "").Select

Every time I get to this point i get an error '1004' - "Application defined
or object defined error"

Can anyone please advise as to what is going on and how to get arround it?

Thanks a bunch
Igor

Bob Phillips

Variable ranges
 
Must be something wrong with the values in Row and col. What do they contain
at that point.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"igorek" wrote in message
...
Hi,
As i write my code the range that i'm referring to changes. To identify

the
lower and the upper limits of the range i use the following

BeginRange = Worksheets("Content").Cells(5, col).Address
EndRange = Worksheets("Content").Cells(Row, col).Address

Now, as i select this range and try to copy it elsewhere i'm trying to use
the following expression:

Worksheets("Content").Range("" & BeginRange & " :" & EndRange & "").Select

Every time I get to this point i get an error '1004' - "Application

defined
or object defined error"

Can anyone please advise as to what is going on and how to get arround it?

Thanks a bunch
Igor




Dave Peterson

Variable ranges
 
If Content isn't the activesheet, you can get this error.

Worksheets("Content").select
Worksheets("Content").Range("" & BeginRange & " :" & EndRange & "").Select

But you could have used:
Worksheets("Content").Range(BeginRange & ":" & EndRange).Select

But I think most would just use:
Worksheets("Content").Range(BeginRange, EndRange).Select



igorek wrote:

Hi,
As i write my code the range that i'm referring to changes. To identify the
lower and the upper limits of the range i use the following

BeginRange = Worksheets("Content").Cells(5, col).Address
EndRange = Worksheets("Content").Cells(Row, col).Address

Now, as i select this range and try to copy it elsewhere i'm trying to use
the following expression:

Worksheets("Content").Range("" & BeginRange & " :" & EndRange & "").Select

Every time I get to this point i get an error '1004' - "Application defined
or object defined error"

Can anyone please advise as to what is going on and how to get arround it?

Thanks a bunch
Igor


--

Dave Peterson

igorek

Variable ranges
 
Bob,

the value of each reflects the cell.address $z$1 for BeginRange and $z$50
for EndRange. So, the variables are fine and are declared as variant.

Thanks for your help



"Bob Phillips" wrote:

Must be something wrong with the values in Row and col. What do they contain
at that point.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"igorek" wrote in message
...
Hi,
As i write my code the range that i'm referring to changes. To identify

the
lower and the upper limits of the range i use the following

BeginRange = Worksheets("Content").Cells(5, col).Address
EndRange = Worksheets("Content").Cells(Row, col).Address

Now, as i select this range and try to copy it elsewhere i'm trying to use
the following expression:

Worksheets("Content").Range("" & BeginRange & " :" & EndRange & "").Select

Every time I get to this point i get an error '1004' - "Application

defined
or object defined error"

Can anyone please advise as to what is going on and how to get arround it?

Thanks a bunch
Igor





Bob Phillips

Variable ranges
 
That value works fine for me. You would get an error if Content is not the
activesheet as Dave suggested, but that is a different error than the one
that you reported. Have you debugged it to see what the range being referred
to is?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"igorek" wrote in message
...
Bob,

the value of each reflects the cell.address $z$1 for BeginRange and $z$50
for EndRange. So, the variables are fine and are declared as variant.

Thanks for your help



"Bob Phillips" wrote:

Must be something wrong with the values in Row and col. What do they

contain
at that point.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"igorek" wrote in message
...
Hi,
As i write my code the range that i'm referring to changes. To

identify
the
lower and the upper limits of the range i use the following

BeginRange = Worksheets("Content").Cells(5, col).Address
EndRange = Worksheets("Content").Cells(Row, col).Address

Now, as i select this range and try to copy it elsewhere i'm trying to

use
the following expression:

Worksheets("Content").Range("" & BeginRange & " :" & EndRange &

"").Select

Every time I get to this point i get an error '1004' - "Application

defined
or object defined error"

Can anyone please advise as to what is going on and how to get arround

it?

Thanks a bunch
Igor







igorek

Variable ranges
 
So foolish of me, thank you guys


All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com