Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Setting a Range depending on variables

Hi

Can somebody help me?
I have two expressions that seem similar to me. But one isn't working.


("rowstart" and "nrmess" are both integer variables with positive
values;
"rng" and "rng2" are both "dim as range")

This works:

Set rng = Measurement.Range(Cells(4070 + rowstart, 4), Cells(4120 +
rowstart, 4))

This doesn't work:

Set rng2 = Sheets("data").Range(Cells(410, nrmess * 3 + 12), Cells(415,
nrmess * 3 + 12))

Can somebody tell me, what is the reason??

Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Setting a Range depending on variables

You should use

With Sheets("data")
.Range(.Cells(410, nrmess * 3 + 12), .Cells(415,nrmess * 3 + 12))
End With

but it may be that nrmess * 3 + 12 is greater than 255


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"mazo" wrote in message
ups.com...
Hi

Can somebody help me?
I have two expressions that seem similar to me. But one isn't working.


("rowstart" and "nrmess" are both integer variables with positive
values;
"rng" and "rng2" are both "dim as range")

This works:

Set rng = Measurement.Range(Cells(4070 + rowstart, 4), Cells(4120 +
rowstart, 4))

This doesn't work:

Set rng2 = Sheets("data").Range(Cells(410, nrmess * 3 + 12), Cells(415,
nrmess * 3 + 12))

Can somebody tell me, what is the reason??

Thank you



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Setting a Range depending on variables

Both are subject to failure. The one that works is because you are working
on the activesheet. When working off the activesheet, all references need to
be qualified

With Worksheets("Data")
Set rng2 = .Range(.Cells(410, nrmess * 3 + 12), _
.Cells(415, nrmess * 3 + 12))
End With

Unqualifed range references refer to the activesheet unless used in a sheet
module. then they refer to the sheet containing the code.

--
Regards,
Tom Ogilvy


"mazo" wrote:

Hi

Can somebody help me?
I have two expressions that seem similar to me. But one isn't working.


("rowstart" and "nrmess" are both integer variables with positive
values;
"rng" and "rng2" are both "dim as range")

This works:

Set rng = Measurement.Range(Cells(4070 + rowstart, 4), Cells(4120 +
rowstart, 4))

This doesn't work:

Set rng2 = Sheets("data").Range(Cells(410, nrmess * 3 + 12), Cells(415,
nrmess * 3 + 12))

Can somebody tell me, what is the reason??

Thank you


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting several variables at the same time BenderBender Excel Programming 1 March 28th 06 09:50 PM
Setting variables to Nothing Matt Jensen Excel Programming 5 January 12th 05 02:25 AM
Setting print area depending on a cell value Rick_Wendt Excel Programming 3 October 21st 04 06:59 PM
Setting a boolean depending on who called the macro Dkline[_2_] Excel Programming 3 June 16th 04 08:30 PM
Setting a print range using variables Mary Branson Excel Programming 3 February 3rd 04 05:23 PM


All times are GMT +1. The time now is 06:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"