Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, could someone please help me modify my deletion code as follows:
I need the following code to be slightly modified so that when a user selects a cell in column Y, then the contents in cells Y:AQ and AY:AZ are deleted. For example: if a user selects cell: Y14, then I need the cell contents Y14:AQ14 and AY14:AZ14 to be deleted. Sub Deleted_Part_1() Dim Y_Column As Range On Error Resume Next ActiveSheet.Unprotect Do Set Y_Column = Application.InputBox("Click in the cell in the Incumbent's Service column that corresponds with the record you wish to delete: ", "Please Choose Correct Cell in the Incumbent's Service column", Cells(ActiveCell.Row, 1).Address, , , , , 8) If Err.Number < 0 Then Call OperationCancelled(True) Exit Sub End If Loop Until Y_Column.Column = 1 Call Deleted_Part_2(Y_Column(1)) ActiveWindow.SmallScroll Down:=-65000 Range("A2").Select End Sub Sub Deleted_Part_2(Where As Range) Dim Msg As String Dim Ans As Long Where.Select Msg = "Click on the <OK Button If You Wish To Continue In Deleting The Current Selected Record, Or Click On the <Cancel Button To Cancel This Operation" Ans = MsgBox(Msg, vbOKCancel) Application.ScreenUpdating = False If Ans = vbOK Then ActiveCell.Rows("1:1").EntireRow.Select Selection.Delete Shift:=xlUp Range("A2").Select With Sheets("Data") 'Following line of code is like selecting the last cell 'in the column and holding the Ctrl key and press Up arrow 'It then names the cell. .Cells(.Rows.Count, "A").End(xlUp).Name = "LastCell" End With Range("A2").Select ActiveWindow.SmallScroll ToRight:=-9 Application.ScreenUpdating = True Msg = "The Selected Record Is Now Deleted" Ans = MsgBox(Msg, vbOKOnly) Range("A2").Select End If If Ans = vbCancel Then Msg = "The Deletion Procedure Has Now Been Cancelled" Ans = MsgBox(Msg, vbOKOnly) Exit Sub End If ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True ActiveSheet.EnableSelection = xlNoRestrictions End Sub Sub OperationCancelled(Optional Cancelled As Boolean) MsgBox "You cancelled this operation." ActiveWindow.SmallScroll ToRight:=-27 End Sub *** Sent via Developersdex http://www.developersdex.com *** |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA code needed for auto deletion upon opening | Excel Discussion (Misc queries) | |||
Row Deletion | Excel Programming | |||
name deletion | Excel Discussion (Misc queries) | |||
Row Deletion | Excel Programming |