Range inside loop defined by two cells contents :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Range inside loop defined by two cells contents
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

alcorjr
Board Master


Joined: 30 Dec 2002
Posts: 342
Location: Costa Rica
Flag: Spain

Status: Offline

 Reply with quote  

Range inside loop defined by two cells contents

Hi guys, this one is trickier than it seems (at least for me). I'm trying to build a loop, but the range subject to looping is not fixed, but depends on the addresses provided by two cells in my sheet, for example:

Range("L17").Value is BA143


Range("L19").Value is BZ143

How can I define Ram as a Range, that will go from BA143 to BZ143 -----contents of Range("L17") to contents of Range("L19") ?????
Thanx to all

icon_eek2.gif

Post Fri Sep 19, 2003 5:19 pm 
 View user's profile Send private message MSN Messenger

earlyd
Board Master


Joined: 11 Dec 2002
Posts: 955

Flag: Usa

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

Dim Ram as string
Ram = Range("L17").Value & ":" & Range("L19").Value

or thanks to some recent knowledge gained from this board:

Ram = [L17] & ":" & [L19]

Post Fri Sep 19, 2003 5:34 pm 
 View user's profile Send private message

alcorjr
Board Master


Joined: 30 Dec 2002
Posts: 342
Location: Costa Rica
Flag: Spain

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

Hy Earlyd, thanks for your interest.
Tried your approach, and indeed,

Ram = [L17] & ":" & [L19] gives me a string-type variable loaded with the two boundaries of my range, but how can I transform that into a range???
If I write;

Dim Rng as Range

Set Range = Ram


I get a mismatch

?????? icon_redface.gif icon_redface.gif

Any ideas????
Thanks.

Post Fri Sep 19, 2003 5:41 pm 
 View user's profile Send private message MSN Messenger

earlyd
Board Master


Joined: 11 Dec 2002
Posts: 955

Flag: Usa

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

See below:

Sub Macro1()
Dim Ram As Range

Set Ram = Range([B21] & ":" & [b22])
Ram.Select
End Sub
icon_smile.gif

Post Fri Sep 19, 2003 5:44 pm 
 View user's profile Send private message

alcorjr
Board Master


Joined: 30 Dec 2002
Posts: 342
Location: Costa Rica
Flag: Spain

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

I got an error:

Method Range of Object Global Failed

icon_confused.gif icon_confused.gif

Any suggestions??

Post Fri Sep 19, 2003 5:49 pm 
 View user's profile Send private message MSN Messenger

earlyd
Board Master


Joined: 11 Dec 2002
Posts: 955

Flag: Usa

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

Sorry - I forgot to tell you to put cell addresses in cells B21 and B22, i.e. cell B21 contains A32 and B22 contains A35. This assumes you want to read the range off your sht.

Post Fri Sep 19, 2003 5:53 pm 
 View user's profile Send private message

alcorjr
Board Master


Joined: 30 Dec 2002
Posts: 342
Location: Costa Rica
Flag: Spain

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

OK. Now, when I analyze the code in the VB editor, and place the cursor on Ram , it does'nt give any value, although the range does appear selected in the sheet.
I'm going to build the loop on it , see what happens. Thanks so much. I'll keep you posted icon_wink.gif icon_wink.gif

Post Fri Sep 19, 2003 5:59 pm 
 View user's profile Send private message MSN Messenger

earlyd
Board Master


Joined: 11 Dec 2002
Posts: 955

Flag: Usa

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

If you want to see the value you could do it in two steps and first build a string that you use in the Set stmt:

Sub Macro1()
Dim Ram As Range
RamString = [B21] & ":" & [b22]
Set Ram = Range(RamString)
Ram.Select
End Sub


Now you can check RamString. We got the Confused to a Wink. Now we're shooting for a smile?? icon_smile.gif

Post Fri Sep 19, 2003 6:03 pm 
 View user's profile Send private message

alcorjr
Board Master


Joined: 30 Dec 2002
Posts: 342
Location: Costa Rica
Flag: Spain

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

Earlyd...YOU'RE THE MAN!!!! icon_biggrin.gif icon_biggrin.gif icon_biggrin.gif

Post Fri Sep 19, 2003 6:25 pm 
 View user's profile Send private message MSN Messenger

earlyd
Board Master


Joined: 11 Dec 2002
Posts: 955

Flag: Usa

Status: Offline

 Reply with quote  

Re: Range inside loop defined by two cells contents

Thanks,

Diane

JUST KIDDING!!! icon_laugh.gif

Post Fri Sep 19, 2003 6:31 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.