charliec83`
New Member
- Joined
- Oct 30, 2017
- Messages
- 2
Hi,
I have built a macro that asks a user to input a development name into an input box. Then the code searches to see if there is a sheet with the name the user enters and deletes that worksheet. It then also removes a range of data on the summary sheet. The code I have so far is as follows:
The only thing I can't work out is how to return a simple error message if the name they type into the input box does not match to a sheet in this workbook (for example they mis-spell it).
Thank you in advance for your help.
I have built a macro that asks a user to input a development name into an input box. Then the code searches to see if there is a sheet with the name the user enters and deletes that worksheet. It then also removes a range of data on the summary sheet. The code I have so far is as follows:
Code:
Sub Delete_Apartment()
Dim Dname As Variant
Dim wks As Worksheet
Dim SearchRow As Integer
Dim DelSelection As Range
Dname = Application.InputBox(Prompt:="Enter Development to delete")
If Dname = False Then Exit Sub
Sheets(Dname).Delete
SearchRow = 25
While SearchRow < 500
If Range("B" & CStr(SearchRow)).Value = Dname Then
Range("B" & CStr(SearchRow)).Offset(-2).Resize(8, 17).Delete
End If
SearchRow = SearchRow + 1
Wend
End Sub
The only thing I can't work out is how to return a simple error message if the name they type into the input box does not match to a sheet in this workbook (for example they mis-spell it).
Thank you in advance for your help.