Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:33:37+00:00 2026-06-02T17:33:37+00:00

the code below works fine. However, when a user doesn’t include anything in the

  • 0

the code below works fine. However, when a user doesn’t include anything in the InputBox or clicks on the ‘Close’ button or inputs a value which doesn’t exist I want it to display a msgbox stating the reason and delete sheets ‘PreTotal’.

Is there a better way to handle user input? Need some help here on how to go about it. Thank you.

Sub Filterme()
    Dim wSheetStart As Worksheet
    Dim rFilterHeads As Range
    Dim strCriteria As String

    Set wSheetStart = ActiveSheet
    Set rFilterHeads = Range("M1", Range("M1").End(xlToLeft))

    With wSheetStart
        .AutoFilterMode = False

        rFilterHeads.AutoFilter

        strCriteria = InputBox("Enter Date - MMDDYY")

        If strCriteria = vbNullString Then Exit Sub

        rFilterHeads.AutoFilter Field:=13, Criteria1:="=*" & strCriteria & "*"
    End With

    Worksheets("PreTotal").UsedRange.Copy

    Sheets.Add.Name = "Total"

    Worksheets("Total").Range("A1").PasteSpecial

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:33:38+00:00Added an answer on June 2, 2026 at 5:33 pm

    Is this what you are trying?

    Change

    If strCriteria = vbNullString Then Exit Sub    
    

    to

    If strCriteria = vbNullString Then
        MsgBox "You choose not to continue"
        Application.DisplayAlerts = False
        Worksheets("PreTotal").Delete
        Application.DisplayAlerts = True
        Exit Sub
    End If
    

    FOLLOWUP

    Thanks @Rout – This worked. One more thing what if the input criteria does not exist in the sheet? How should I tackle that? – user823911 11 mins ago

    Is this what you are trying? Also if you are filtering the range based on Col M (1st Col in the range) then change the line

    rFilterHeads.AutoFilter Field:=13, Criteria1:="=*" & strCriteria & "*"
    

    to

    rFilterHeads.AutoFilter Field:=1, Criteria1:="=*" & strCriteria & "*"
    

    CODE

    Sub Filterme()
        Dim wSheetStart As Worksheet
        Dim rFilterHeads As Range, aCell As Range
        Dim strCriteria As String
    
        Set wSheetStart = ActiveSheet
        Set rFilterHeads = Range("M1", Range("M1").End(xlToLeft))
    
        With wSheetStart
            .AutoFilterMode = False
    
            strCriteria = InputBox("Enter Date - MMDDYY")
    
            If strCriteria = vbNullString Then
                MsgBox "You choose not to continue"
                Application.DisplayAlerts = False
                Worksheets("PreTotal").Delete
                Application.DisplayAlerts = True
                Exit Sub
            End If
    
            Set aCell = .Columns(13).Find(What:=strCriteria, LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
    
            If Not aCell Is Nothing Then
                MsgBox "Search Criteria Not Found"
                Exit Sub
            End If
    
            rFilterHeads.AutoFilter
    
            rFilterHeads.AutoFilter Field:=13, Criteria1:="=*" & strCriteria & "*"
    
            Sheets.Add.Name = "Total"
            Worksheets("PreTotal").UsedRange.Copy
            Worksheets("Total").Range("A1").PasteSpecial
        End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works fine at 1280x800, however, if I add another thumbnail, the
The code below works fine, everything is associated nicely. However, it's not what I
the code below works fine but it takes an absolute age to run. How
Currently my code below works fine but it's a bit of overkill. In my
I'm trying to open a ZIP file in JAVA. The code below works fine
My below code works fine and is used to populate a <select> item with
The code I have below works fine but I'm sure it could be more
The code below is creating a server to communicate with clients.This code works fine
I have the code below, which works fine it can be viewed for an
The uncommented code below yields an OperationalError: near? while the commented lines works fine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.