Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 14th, 2003, 12:44 PM
michaelpepera michaelpepera is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 michaelpepera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Selecting Multiple Ranges using Cells(i, j) Notation

I am trying to select multiple ranges in an Excel macro. The ranges are being generated from values of integers created elsewhere.

I have seen examples to select multiple ranges using the standard "A1:A5" notation, but cannot get it to work for the Cells(i, j) notation. Here is the offending code.

Code:


    Set varRangeSelect1 = Range(Cells(10, 2), Cells(11, 2))
    Set varRangeSelect2 = Range(Cells(13, 2), Cells(intCountRow, 2))
    Set varRangeSelect3 = Union(Range(varRangeSelect1), Range(varRangeSelect2))
    Range(varRangeSelect).Select


When the last line is executed, I get the following error:

Run Time Error 104
Method 'Range' of object '_Global' failed

Of course the help menu in Visual Basic for Excel is most unhelpful.

Any suggestions on how I can make this work would be greatly appreciated.

Thanks,

Michael Pepera

Reply With Quote
  #2  
Old August 15th, 2003, 08:01 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Are you sure it shouldn't be:
Code:
Range(varRangeSelect3).Select

Reply With Quote
  #3  
Old August 18th, 2003, 12:35 PM
michaelpepera michaelpepera is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 michaelpepera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes you are right. However, the problem still remains the same!

Thanks for the reply,

Michael Pepera

Reply With Quote
  #4  
Old October 25th, 2003, 10:28 PM
kegobeer's Avatar
kegobeer kegobeer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Panama City Beach, FL
Posts: 3 kegobeer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This worked for me:

Set varRangeSelect1 = Range(Cells(10, 2), Cells(11, 2))
Set varRangeSelect2 = Range(Cells(13, 2), Cells(intCountRow, 2))
Set varRangeSelect3 = Union(varRangeSelect1, varRangeSelect2)
varRangeSelect.Select

This would also work:

Set varRangeSelect3 = Union(Range(Cells(10,2), Cells(11,2)), Range(Cells(13,2), Cells(intCountRow,2)))
varRangeSelect3.Select

Hope that helps you out.

Reply With Quote
  #5  
Old October 27th, 2003, 01:41 PM
michaelpepera michaelpepera is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 michaelpepera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the help! Now that I look back at the code, I ended doing something slightly different in order to work around the problem.

However, it is good to know how this will function for the future.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Selecting Multiple Ranges using Cells(i, j) Notation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway