LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Member
 
Posts: 84
Default Input Box Error Handler

Help Please! I need an error handler code for this macro. I've optioned out several attempts to solve this problem. This code works, but if the Cancel button is clicked is wants to make a copy of the "CategoryCopy" sheet. I need the code to exit the sub if the Cancel button is pressed or if there is a duplicate sheet name entered.

Thanks in advance for your help!



Sub report_test()

'On Error GoTo ErrorHandler

Dim name As Variant
name = Application.InputBox("BE CAREFUL TO NOT DUPLICATE A SHEET NAME!" & vbNewLine & vbNewLine & "Please Enter A ""NEW"" Name For This Category:", "TAX TOOL EXPRESS")

'Dim sht As Worksheet, rFound As Range
'On Error Resume Next

'For Each sht In Sheets
'Set rFound = ThisWorkbook.Worksheets("CategoryCopy").Range("D4" ).Find(sht.name)
'If Not rFound Is Nothing Then
'MsgBox " OOPS!" & vbNewLine & vbNewLine & " THAT WORKSHEET NAME ALREADY EXISTS!" & vbNewLine & vbNewLine & "Either delete the existing worksheet that has the name you are trying to use, or choose another name for the new worksheet." & vbNewLine & vbNewLine & "To delete the existing worksheet simply right click on it's sheet tab and select ""Delete"" from the pop up action menu. You will be prompted to confirm your deletion.", vbCritical, " TAX TOOL EXPRESS"

'End If
'Exit Sub


'If name = Worksheets("CategoryCopy").Range("D4") Then Exit Sub
Worksheets("CategoryCopy").Range("D4") = name
'If name = Worksheets("CategoryCopy").Range("D4") Then Exit Sub
Worksheets("CategoryCopy").Range("D7:D257").Clear


'ErrorHandler: MsgBox " OOPS!" & vbNewLine & vbNewLine & " THAT WORKSHEET NAME ALREADY EXISTS!" & vbNewLine & vbNewLine & "Either delete the existing worksheet that has the name you are trying to use, or choose another name for the new worksheet." & vbNewLine & vbNewLine & "To delete the existing worksheet simply right click on it's sheet tab and select ""Delete"" from the pop up action menu. You will be prompted to confirm your deletion.", vbCritical, " TAX TOOL EXPRESS"

'Exit Sub

Application.ScreenUpdating = False


Worksheets("Final Filtering").Range("G7").Select
Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Sheets("CategoryCopy").Visible = True
Sheets("CategoryCopy").Select
Range("D7").Select
Selection.PasteSpecial Paste:=xlValues

Dim iRange As Range
Dim iCells As Range

Set iRange = Range("D7:D257")

For Each iCells In iRange
iCells.BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThin

Next iCells


'Call Copy_Paste_StatisticsReport
'On Error GoTo ErrorHandler

Sheets("CategoryCopy").Copy after:=Sheets("FINAL FILTERING")
ActiveSheet.name = Sheets("CategoryCopy").Range("D4")
ActiveSheet.Range("D5:H5").FormulaHidden = True
ActiveSheet.Range("E7:H257").FormulaHidden = True
ActiveSheet.Protect
ActiveSheet.Range("D4").Select


ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveSheet.DisplayPageBreaks = False



Sheets("CategoryCopy").Visible = xlSheetVeryHidden
Worksheets("Final Filtering").Select
Selection.AutoFilter
Range("A2").Comment.Visible = False
Range("A6").Select

'ErrorHandler: MsgBox " OOPS!" & vbNewLine & vbNewLine & " THAT WORKSHEET NAME ALREADY EXISTS!" & vbNewLine & vbNewLine & "Either delete the existing worksheet that has the name you are trying to use, or choose another name for the new worksheet." & vbNewLine & vbNewLine & "To delete the existing worksheet simply right click on it's sheet tab and select ""Delete"" from the pop up action menu. You will be prompted to confirm your deletion.", vbCritical, " TAX TOOL EXPRESS"
'On Error Resume Next
'Exit Sub
'Application.DisplayAlerts = False
'Sheets("False").Visible = xlSheetVeryHidden
End Sub
 
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
Error handler linto Excel Discussion (Misc queries) 1 February 11th 10 12:17 PM
Error Handler displaying message when no error Code Numpty Excel Programming 5 September 28th 09 07:25 PM
Form Err.Raise error not trapped by entry procedure error handler [email protected] Excel Programming 1 February 8th 06 10:19 AM
Read txt file for input error handler Chirs[_2_] Excel Programming 2 June 30th 05 12:40 PM
Error Handler dht[_2_] Excel Programming 5 August 19th 04 08:51 AM


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