Is the Activecell within a range

KeithGrindle

New Member
Joined
Apr 11, 2002
Messages
5
Hi! I'm new to the list so I hope I do things correctly. If not please bare with me. I have searched the archives but I could only find similar questions and not the answers. I must be doing something wrong.

I would like to programmatically find out if the activecell is within a certain range and if it is I would like other code to execute. Here is the code that I have now. It is failing in the first 3 lines I believe.

Dim Actvcel As Range
Dim WallARange As Range
Dim Width As Double

Set Actvcel = ActiveCell
Set WallARange = Worksheets("Layout").Range("WallA")

If Actvcel.Parent.Parent.Name = WallARange.Parent.Parent.Name Then
If Actvcel.Parent.Name = WallARange.Parent.Name Then
If Union(Actvcel, WallARange).Address = WallARange.Name Then

If Actvcel.Value = "hwt" Or Actvcel = "hwa" Then
Width = InputBox("Please enter the width for this HVAC_
Window", "HVAC Window Width")
i = ActiveCell.Range("WallARange").Rows.Count
Worksheets("Formulas").Range("DO2:DO26").Rows_
(i).Value = Width
End if
End if
End if
End if

Many Thanks in Advance

Keith
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi Keith
There is not too much wrong except fro the
range reference when using Union will refer
to an array of ranges...wallarange will refer
to a range referencing your wbook name.

If I could suggest another method.
Try this....not too sure of all your requiesites but ....<pre/>
Dim Actvcel As Range
Dim WallARange As Range
Dim OK As Range
Dim Width As Double
Dim i As Integer

Set Actvcel = ActiveCell
Set WallARange = Worksheets("Layout").Range("WallA")

On Error Resume Next
Set OK = Application.Intersect(Actvcel, WallARange)
If Err Then Exit Sub 'wrong range/sheet

If Not OK Is Nothing Then
If Actvcel.Value = "hwt" Or Actvcel = "hwa" Then
Width = Application.InputBox("Please enter the width for this HVAC Window", "HVAC Window Width", Type:=1)
If Width = 0 Then Exit Sub
i = WallARange.Rows.Count
Worksheets("Formulas").Range("DO2:DO26").Rows(i).Value = Width
End If
End If</pre>



_________________
Kind Regards,<font size=+2><font color="red"> I<font color="blue">van<font color="red"> F M</font color="blue">oala</font></font></font>
<font color="green">[url]http://www.gwds.co.nz/ - Under Construction[/url]
This message was edited by Ivan F Moala on 2002-04-12 14:40
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,267
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top