george hart
Board Regular
- Joined
- Dec 4, 2008
- Messages
- 241
Hi
The code below works fine, in that you can enter data and it will find it and delete the rows. However, it falls over when you enter data that isn't there.
Any way I can get a message pop up when this happens to say data not found and then end sub??
Dim Answer As String
Answer = MsgBox("Are you sure you want to remove a KPI?", vbYesNo)
If Answer <> vbYes Then Exit Sub
data = (InputBox("Enter the KPI you want to remove"))
Sheets(Array("Actual Operations KPI", "Targets Operations KPI", _
"Data provider - Definition")).Select
Sheets("Actual Operations KPI").Activate
Cells.Find(What:=(data), After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.EntireRow.Delete
Sheets("Current Period-YTD Ops KPI").Select
Cells.FindNext(After:=ActiveCell).Activate
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
The code below works fine, in that you can enter data and it will find it and delete the rows. However, it falls over when you enter data that isn't there.
Any way I can get a message pop up when this happens to say data not found and then end sub??
Dim Answer As String
Answer = MsgBox("Are you sure you want to remove a KPI?", vbYesNo)
If Answer <> vbYes Then Exit Sub
data = (InputBox("Enter the KPI you want to remove"))
Sheets(Array("Actual Operations KPI", "Targets Operations KPI", _
"Data provider - Definition")).Select
Sheets("Actual Operations KPI").Activate
Cells.Find(What:=(data), After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.EntireRow.Delete
Sheets("Current Period-YTD Ops KPI").Select
Cells.FindNext(After:=ActiveCell).Activate
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp