ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable Range in Macro not working. (https://www.excelbanter.com/excel-programming/378021-variable-range-macro-not-working.html)

Nicolas

Variable Range in Macro not working.
 
Hi all,
I´m trying to select a range by using 2 integer variables and I get
the following Error msg
----------------------------------------------------
Run-time error '1004':

Application-defined or object-defined error
----------------------------------------------------

The sitax is as follows:

Range("A" & fila & ":" & "F" & ultimafila).Select

Should i type it in a different way ?
All suggestions welcome.
BR.
NICOLAS

Jim Thomlinson

Variable Range in Macro not working.
 
The syntax you have should work (not the way i would do it but it should
work). The only thing I would add is that the variable values can not be 0
and must be less than 65,536... To that end you should be using long and not
integer as integer ends at 32k... If it was me I would be more inclined to do
something like...

Range(cells(fila, "A"), cells(ultimafila, "F")).Select

--
HTH...

Jim Thomlinson


"Nicolas" wrote:

Hi all,
I´m trying to select a range by using 2 integer variables and I get
the following Error msg
----------------------------------------------------
Run-time error '1004':

Application-defined or object-defined error
----------------------------------------------------

The sitax is as follows:

Range("A" & fila & ":" & "F" & ultimafila).Select

Should i type it in a different way ?
All suggestions welcome.
BR.
NICOLAS


Snake Plissken[_2_]

Variable Range in Macro not working.
 
| Hi all,
| I´m trying to select a range by using 2 integer variables and I get
| the following Error msg
| ----------------------------------------------------
| Run-time error '1004':
|
| Application-defined or object-defined error
| ----------------------------------------------------
|
| The sitax is as follows:
|
| Range("A" & fila & ":" & "F" & ultimafila).Select
|

after you press debug button the debbuger stops on the line above ? in my
sheet the same code works fine
(I assume that these 2 variables give in fact proper values and u monitor it
somehow)



Nicolas

Variable Range in Macro not working.
 
Hi Jim,

thnx for ur reply in a first place, I´ve tried the code you suggested
and the result is exactly the same. But if i use the porperty COPY instead of
SELECT it doesn´t return the error. Any reason why this should be happening ?
(I´m running Excel 2003)
Tnhx.

"Jim Thomlinson" wrote:

The syntax you have should work (not the way i would do it but it should
work). The only thing I would add is that the variable values can not be 0
and must be less than 65,536... To that end you should be using long and not
integer as integer ends at 32k... If it was me I would be more inclined to do
something like...

Range(cells(fila, "A"), cells(ultimafila, "F")).Select

--
HTH...

Jim Thomlinson


"Nicolas" wrote:

Hi all,
I´m trying to select a range by using 2 integer variables and I get
the following Error msg
----------------------------------------------------
Run-time error '1004':

Application-defined or object-defined error
----------------------------------------------------

The sitax is as follows:

Range("A" & fila & ":" & "F" & ultimafila).Select

Should i type it in a different way ?
All suggestions welcome.
BR.
NICOLAS


Nicolas

Variable Range in Macro not working.
 
By the way, just figured out thar i get the same error with code as simple as
cells(1,1).select range ("A1").select, etc.
Any clues on this ? (it´s driving me insane........)

"Nicolas" wrote:

Hi Jim,

thnx for ur reply in a first place, I´ve tried the code you suggested
and the result is exactly the same. But if i use the porperty COPY instead of
SELECT it doesn´t return the error. Any reason why this should be happening ?
(I´m running Excel 2003)
Tnhx.

"Jim Thomlinson" wrote:

The syntax you have should work (not the way i would do it but it should
work). The only thing I would add is that the variable values can not be 0
and must be less than 65,536... To that end you should be using long and not
integer as integer ends at 32k... If it was me I would be more inclined to do
something like...

Range(cells(fila, "A"), cells(ultimafila, "F")).Select

--
HTH...

Jim Thomlinson


"Nicolas" wrote:

Hi all,
I´m trying to select a range by using 2 integer variables and I get
the following Error msg
----------------------------------------------------
Run-time error '1004':

Application-defined or object-defined error
----------------------------------------------------

The sitax is as follows:

Range("A" & fila & ":" & "F" & ultimafila).Select

Should i type it in a different way ?
All suggestions welcome.
BR.
NICOLAS


Snake Plissken[_2_]

Variable Range in Macro not working.
 
very strange!
check the references in VBA editor (tools\references) maybe you don't have
references set to apropriate libraries...



Nicolas

Variable Range in Macro not working.
 
I know, i had to overcome the problem by referencing the whole code...
Worksheets("Blk Cont D Historico").Range(Worksheets("Blk Cont D
Historico").Cells(fila, "A"), Worksheets("Blk Cont D
Historico").Cells(ultimafila, "F")).Select

now it works, but it is still pretty anoying.
Thanks anyway for your help guys.

"Snake Plissken" wrote:

very strange!
check the references in VBA editor (tools\references) maybe you don't have
references set to apropriate libraries...





All times are GMT +1. The time now is 05:18 PM.

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