Consulting

Results 1 to 3 of 3

Thread: VBA Code to Search and Select Sheet through Input BOX

  1. #1

    VBA Code to Search and Select Sheet through Input BOX

    hi I have this code from excel.com but how do I just search the sheet and select it through input box also is there any way the input box remains always in the sheet and does not go away requesting your help many thanks


    Sub Macro()
    
    Dim strNewName As String
    Dim ws As Worksheet
    Dim boolFound As Boolean
    
    strNewName = InputBox("Please enter a valid Worksheet Name:", "New Worksheet Name")
    For Each ws In Worksheets
    If ws.Name Like strNewName Then boolFound = True: Exit For
    Next
    
    If boolFound = True Then
    MsgBox ("Name Already Exisits, Please enter a new name")
    Sheets(strNewName).Select
    
    Else
    Sheets.Add.Name = strNewName
    End If
    
    End Sub

  2. #2
    hi plz consider this thread solved in mr excel.com by mumps

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps this will do what you want
    Sub test()
        Dim uiName As String
    
        Do
            uiName = Application.InputBox("Enter new sheet name", Type:=2)
            If uiName = "False" Or Trim(uiName) = vbNullString Then Exit Do
            
            On Error Resume Next
            If LCase(Worksheets(uiName).Name) <> LCase(uiName) Then
                Err.Clear
                With ThisWorkbook
                    With .Sheets.Add(after:=.Sheets(.Sheets.Count))
                        .Name = uiName
                        If Err Then
                            MsgBox Error
                            Application.DisplayAlerts = False
                            .Delete
                            Application.DisplayAlerts = True
                        End If
                        On Error GoTo 0
                    End With
                End With
            Else
                Err.Clear
                On Error GoTo 0
                MsgBox "old name"
            End If
        Loop Until False
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •