ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert/delete rows (https://www.excelbanter.com/excel-programming/341325-insert-delete-rows.html)

JohnUK

Insert/delete rows
 
Hi again,
I have another problem to solve. The code below is my attempt to stop a
macro from inserting or deleting rows if B9 was included, but for some reason
its not behaving as I thought it would. What am I doing wrong?

If ActiveCell = B9 Then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

Many thanks in advance

John


Tom Ogilvy

Insert/delete rows
 
If Not Intersect(selection,Range("B9")) is Nothing then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

or do you want to guard against any row insertion above or at row 9

If Selection.Row <= 9 then


--
Regards,
Tom Ogilvy


"JohnUK" wrote in message
...
Hi again,
I have another problem to solve. The code below is my attempt to stop a
macro from inserting or deleting rows if B9 was included, but for some

reason
its not behaving as I thought it would. What am I doing wrong?

If ActiveCell = B9 Then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

Many thanks in advance

John




K Dales[_2_]

Insert/delete rows
 
Your code only gives the message if the ActiveCell is B9 - it sounds like you
want it to run if the selected row includes row 9 regardless if B9 is the
active cell? If I have that right, then this would do it:
If ActiveCell.Row = 9 Then...
--
- K Dales


"JohnUK" wrote:

Hi again,
I have another problem to solve. The code below is my attempt to stop a
macro from inserting or deleting rows if B9 was included, but for some reason
its not behaving as I thought it would. What am I doing wrong?

If ActiveCell = B9 Then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

Many thanks in advance

John


JohnUK

Insert/delete rows
 
Tom
Something as simple as that:

If Selection.Row <= 9 then

I need to be shot
Many thanks it works a treat
John
PS and thank you for your help "K"

"Tom Ogilvy" wrote:

If Not Intersect(selection,Range("B9")) is Nothing then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

or do you want to guard against any row insertion above or at row 9

If Selection.Row <= 9 then


--
Regards,
Tom Ogilvy


"JohnUK" wrote in message
...
Hi again,
I have another problem to solve. The code below is my attempt to stop a
macro from inserting or deleting rows if B9 was included, but for some

reason
its not behaving as I thought it would. What am I doing wrong?

If ActiveCell = B9 Then
MsgBox "Please do not select to insert or delete from this row" &
vbNewLine & _
"" & vbNewLine & _
" Please un-select and try again" & vbNewLine & _
" ", , "ERROR"
Exit Sub
End If

Many thanks in advance

John






All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com