Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Delete Line Macro - IF Function


Hi,

I'm trying to create a macro that deletes a line from a spreadsheet i am
developing. The code is below, its works fine but I would like to specify
rows that the macro will not delete.

I need to know the code that specifies either - to end the macro if a
specific row is chosen for deletion. Or even better would be the code that
specifies that the macro will only delete a line within a specific named
range.


Application.ScreenUpdating = False
ActiveSheet.Unprotect "gpro"
varAnswer = MsgBox("Delete Line?", vbOKCancel, "Please Confirm")
If varAnswer = 1 Then
If Range("D17") = "2" Then
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp
Rows("180:180").Select
Selection.EntireRow.Hidden = True
Range("E13").Select
Else
End If
Else: End
End If
ActiveSheet.Protect "gpro", DrawingObjects:=True, Contents:=True,
Scenarios:=True

End help would be great.
Phil
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Delete Line Macro - IF Function

Assuming your named range is called "ProtectedRange" I would do it like this:

varAnswer = MsgBox("Delete Line?", vbOKCancel, "Please Confirm")
If ((varAnswer = 1) and
Application.Intersect(Range("ProtectedRange"),Sele ction) Is Nothing) Then ...

The Intersect method sees if there is any "overlap" between the selected
range and the range you want to protect from deletion - if none, then do the
delete...
HTH

"PW11111" wrote:


Hi,

I'm trying to create a macro that deletes a line from a spreadsheet i am
developing. The code is below, its works fine but I would like to specify
rows that the macro will not delete.

I need to know the code that specifies either - to end the macro if a
specific row is chosen for deletion. Or even better would be the code that
specifies that the macro will only delete a line within a specific named
range.


Application.ScreenUpdating = False
ActiveSheet.Unprotect "gpro"
varAnswer = MsgBox("Delete Line?", vbOKCancel, "Please Confirm")
If varAnswer = 1 Then
If Range("D17") = "2" Then
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp
Rows("180:180").Select
Selection.EntireRow.Hidden = True
Range("E13").Select
Else
End If
Else: End
End If
ActiveSheet.Protect "gpro", DrawingObjects:=True, Contents:=True,
Scenarios:=True

End help would be great.
Phil

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
Macro data selection line delete Frantic Excel-er Excel Discussion (Misc queries) 0 May 31st 05 11:46 PM
Macro to delete first line of 200+ files Bob Dobalina Excel Discussion (Misc queries) 2 May 26th 05 10:04 PM
Macro to delete line Kevin Depree Excel Programming 2 September 1st 04 12:29 PM
Macro/Function to delete......... JC[_9_] Excel Programming 1 August 24th 04 03:35 AM
Help! Excel Macro Delete function!! wmcray[_3_] Excel Programming 3 August 3rd 04 12:19 PM


All times are GMT +1. The time now is 01:29 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"