Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Verify Active Cell is within a Range that changes as cell is delet

I'd like to verify a cell is within a range of rows prior to allowing the
macro to delete the row. It's easy enough I know if the range of rows is
constant; but if you're deleting the rows within the range - then the range
is shrinking and using constants (as in my example below) probably won't
work. Any ideas?

If ActiveCell.Row 6 AND ActiveCell.Row <30 Then
ActiveCell.Row.Delete Else
MsgBox "Nope - can't delete the row."
End If


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Verify Active Cell is within a Range that changes as cell is delet

How are the row number limits determined? If you have a defined
name for the range, you can write

If Not Application.Intersect(ActiveCell, Range("Your")) Is
Nothing Then
ActiveCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Shannon" wrote in message
...
I'd like to verify a cell is within a range of rows prior to
allowing the
macro to delete the row. It's easy enough I know if the range
of rows is
constant; but if you're deleting the rows within the range -
then the range
is shrinking and using constants (as in my example below)
probably won't
work. Any ideas?

If ActiveCell.Row 6 AND ActiveCell.Row <30 Then
ActiveCell.Row.Delete Else
MsgBox "Nope - can't delete the row."
End If




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Verify Active Cell is within a Range that changes as cell is delet

You probably want to use a named range as it can gor and shrink as the sheet
is changed. Then you can just check to see if the active cell is within the
named range something like this...

dim rng as range

on error resume next
set rng = intersect(activecell, range("MyRange"))
on error goto 0
if rng is nothing then
activecell.entirerow.delete
else
msgbox "Sorry. No can do"
endif

--
HTH...

Jim Thomlinson


"Shannon" wrote:

I'd like to verify a cell is within a range of rows prior to allowing the
macro to delete the row. It's easy enough I know if the range of rows is
constant; but if you're deleting the rows within the range - then the range
is shrinking and using constants (as in my example below) probably won't
work. Any ideas?

If ActiveCell.Row 6 AND ActiveCell.Row <30 Then
ActiveCell.Row.Delete Else
MsgBox "Nope - can't delete the row."
End If


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
use active cell to determine range Gizmo Excel Discussion (Misc queries) 2 March 31st 08 04:55 AM
Clearly seeing active cell in a range dsa Excel Discussion (Misc queries) 2 March 24th 08 03:22 PM
Verify Active Cell Brian Matlack[_33_] Excel Programming 2 November 29th 05 06:04 PM
Active cell is within a specific range Todd Huttenstine Excel Programming 1 November 1st 04 04:57 PM
How to verify a cell is in a named range Terry Lowe[_2_] Excel Programming 1 July 14th 04 01:06 AM


All times are GMT +1. The time now is 03:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"