Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default InputBox code

Hi Frank. Thanks.
By valid, I mean that the user enters in the name of a worksheet that exists
in the active workbook (the workbook has a number of sheets named
chronologically by month and year). What I'm concerned with is how to handle
an error if/when the user doesn't enter anything and there's an empty string.
This code is working for me. Now how should I code the sub to end the entire
macro when the user clicks the Cancel button?
John

"Frank Kabel" wrote:

Hi
how do you define a 'valid' string?

For your second question you could use something like

Dim wksname
Dim wks as worksheet
wksname=inputbox ("Enter a name")

on error resume next
set wks = activeworkbook.worksheets(wksname)
on error goto 0
if wks is nothing then
msgbox "not a valid sheetname"
else
msgbox "You have selected sheet: " & wks.name
end if


--
Regards
Frank Kabel
Frankfurt, Germany


baehrjf wrote:
New to programming Excel VB, so bear with me....
I want to have a InputBox which will activate a worksheet in a
workbook that was just opened with Workbooks.Open. I am able to
build the InputBox with Application.InputBox and activate the sheet
with Sheets.Activate, but what I need help with is to write the
syntax to 1. requires the user to either enter a valid string or end
the macro with a cancel commandbutton; and 2. handle the error if the
user enters an invalid worksheet name (invalid because it's not in
the workbook, nothing more complex than that). Thanks in advance for
any help.

John



Reply
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
InputBox peyman Excel Discussion (Misc queries) 4 September 28th 07 04:53 PM
Inputbox with VBA Jeff Excel Discussion (Misc queries) 3 January 19th 06 05:18 PM
InputBox code Mark Excel Programming 0 August 12th 04 08:25 AM
Inputbox sadik Excel Programming 3 February 19th 04 07:14 PM
Excel Macro Code invoking InputBox. Andrew Thorne Excel Programming 0 July 30th 03 10:23 PM


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