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

This may not be the most elegant code you've ever seen, but I've discovered
that many other people have struggled with vbCancel in InputBox es, so I'm
pretty pleased with what I've come up with your help. With the InputBox,
vbCancel and "" both return "False", I set my InputBox with a default
string--a useful prompt in a way--that the user must replace with a good
sheet name before the macro will work. Leaving the default string results in
a msgbox and the InputBox to reload. If the user clears the box and enters
"", then the procedure ends as if they'd cancelled. Too bad.

I'd be happy to hear if there are ways I can clean this up, though. I always
manage to leave room for improvement.

Sub InputSheetName()
Dim Message As String
Dim Title As String
Dim wksname
Dim wks As Worksheet
' Set prompt message.
Message = "Enter a sheet name in MthYYYY format to select the sheet with
the exchange rates you wish to use to update the converter."
' Set title.
Title = "Select Desired Sheet"
' Display Input Box.
wksname = InputBox(Message, Title, "MthYYYY")
' In case user clicks the Okay button before entering a sheet name.
If wksname = "MthYYYY" Then
MsgBox "Not a valid sheetname. Re-enter a valid name."
InputSheetName
End If
' In case user clicks the Cancel button.
If wksname = "" Then
MsgBox ("Ending Macro")
End
End If
' Error Handler in case user enters and invalid sheet name.
On Error Resume Next
Set wks = ActiveWorkbook.Worksheets(wksname)
On Error GoTo 0
If wks Is Nothing Then
MsgBox "Not a valid sheetname. Re-enter a valid name."
InputSheetName
Else
Sheets(wksname).Activate 'Activates the desired worksheet
End If
' Selects and copies to the clipboard the desired range of cells on the
active sheet.
Range("F12:F52").Select
Selection.Copy

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 code baehrjf Excel Programming 0 August 12th 04 07:13 PM
InputBox code Mark Excel Programming 0 August 12th 04 08:25 AM
Inputbox sadik Excel Programming 3 February 19th 04 07:14 PM
inputbox Lawson Excel Programming 2 October 7th 03 08:58 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 07:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"