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 July 25th, 2003, 02:28 AM
moronmaster moronmaster is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 10 moronmaster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Determining wether current cell/range within a specified range

Hi,
I am trying to write a macro for excel spreadsheet.
I am trying to find some function or method to determine wether a particular cell is currently within the specified range or not.

A simple example to illustrate question:

Dim Action_Range as Range
Set Action_Range = Range("A1:H:10")

Dim Current_Range as Range
Set Current_Range = ActiveCell

If Current_Range is part of the Action Range then
'do something
Else
'ignore
End if

Can somebody give some suggestions?
Thanks

Reply With Quote
  #2  
Old July 29th, 2003, 07:37 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
This is actually a rather good question. There is probably a better way of doing it, but this is how I would have done it (please not that my way isn't always the best or the easiest, but it does usually work )

I would have created a function (that returns a true or false). This function checks if the current startrow (Current_Range.cells.row) is larger than the action startrow (Action_rage.cells.row) and if the current number of rows (Current_Range.Rows.Count) + the current startrow is smaller than the action number of rows (Action_Range.Rows.Count) + the action start row. The same for the columns.

In other words:
Code:
If (Current_Range.Cells.Row >= Action_Range.Cells.Row) And ((Current_Range.Rows.Count + Current_Range.Cells.Row) <= (Action_Range.Rows.Count + Action_Range.Cells.Row)) Then
    bTemp = true
Else
    bTemp = false
End If
'Same for columns.


Oh yes, typing error: the Range("A1:H:10") should be Range("A1:H10")

Reply With Quote
  #3  
Old August 4th, 2003, 05:28 AM
moronmaster moronmaster is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 10 moronmaster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
After some mucking around i actually used this method:

If Intersect(Current_Range, Action_Range) Is Nothing Then
'do nothing
Else
'do some action
End if

Just FYI.

Thanks Silian for your suggestion and yeah that was a typo by me...

Reply With Quote
  #4  
Old August 4th, 2003, 05:33 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I knew that there was a better way 2 do it! Glad u figured it out (and posted it - now I can use it as well should I need it )

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Determining wether current cell/range within a specified range


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 5 hosted by Hostway