|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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") |
|
#3
|
|||
|
|||
|
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... |
|
#4
|
||||
|
||||
|
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
) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Determining wether current cell/range within a specified range |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|