Excel/inputbox help

Advertisement


Question
Hi Jerry,

I have got a workbook with a number of worksheets in it.

in this I have a person and then a corrosponding data sheet.

so for example I have one worksheet called Joe Bloggs and then one called Joe Bloggs data.

i am trying to use a macro so that if a nuser needs to amend a persons time information it goes directly to the data sheet.

i am currently using the following macro.

Sub opensheet()
'
' opensheet Macro
Dim sPrompt As String
Dim sDefault As String


sPrompt = "Please enter the sheet name to update the records"
sDefault = "data"
   ShtName = InputBox(sPrompt, sDefault)
   Sheets(ShtName).Visible = xlSheetVisible
   Sheets(ShtName).Select
End Sub

However the user has to enter Joe Bloggs data to be able to open the sheet.

is there a method so the user only has to enter Joe bloggs to be able to enter the relevant sheet?

Hope this makes sense.

Answer
Try this:

Option Explicit

Sub OpenSheet()
Dim shName As String, ws As Worksheet

shName = Application.InputBox("Please enter the sheet name to update the records", "Search string", "data", Type:=2)
If shName = "False" Then Exit Sub

For Each ws In Worksheets
    If InStr(ws.Name, shName) > 0 Then
        With ws
            .Visible = xlSheetVisible
            .Activate
        End With
        Exit Sub
    End If
Next ws

MsgBox "No sheet was found with the string in the sheet name"
End Sub

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jerry Beaucaire

Expertise

Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files

Experience

Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files ===================== I have been offering free assistance as an Excel aid on many web sites for many years: (http://www.excelforum.com - JBeaucaire) ======== (http://www.askmehelpdesk.com/spreadsheets - JBeaucaire) ======= (http://www.mrexcel.com/forum - jbeaucaire)

Education/Credentials
Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition

Awards and Honors
Microsoft Excel MVP 2010

©2016 About.com. All rights reserved.