1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: input box data to run macro

Discussion in 'Business Applications' started by mrl, Dec 29, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. mrl

    mrl Thread Starter

    Joined:
    Aug 12, 2007
    Messages:
    327
    Hi, Happy New Year
    I'm having a mind freeze.
    I'm trying to have an input box come up asking "what Month?" and then going to that month. I range named each month. I can't seem to get started.


    Mike :confused:
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    I assume you are using Excel? If so can you post a sample workbook?

    Rollin
     
  3. mrl

    mrl Thread Starter

    Joined:
    Aug 12, 2007
    Messages:
    327
    Hi Rollin

    Yes Excel 2007. I Want to have a box come up after I click on a macro button and ask "what Month?", Then, depending on the input (January, February, March, etc.) I want go to that month. I ranged name each month: This is what I have so far:
    HTML:
    Sub selectmonth()
    Dim strName As String
        strName = InputBox("                       What Month? ) 
        If strName = vbNullString Then
        Exit Sub
        Else
    End sub
    
    I figured to have a macro for each range name (month) I'm still learning about macros and wanted to use something I already know.

    Mike
     

    Attached Files:

  4. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Here is the modified code. Using an inputbox is bad practice in my opinion because there is too much opportunity for the user to enter data into the inputbox that is not valid or spelled correctly. You are better off creating a list of the allowed months in an unused range in your workbook and then use data validation in a cell to force the user to select one of the allowable month values. The macro code could then be fired using an embedded button located somewhere on your worksheet. Another option would be to create your own form and use a listbox or combobox to select the month.

    Code:
    Sub SelectMonth()
    
    Dim strName As String
    
    strName = InputBox("Enter Month")
    
    If strName = vbNullString Then
      Exit Sub
    Else
    
      Select Case strName
    
         Case "January"
            Application.Goto Reference:="January"
         Case "February"
           Application.Goto Reference:="February"
         Case Else
         MsgBox ("MONTH NOT FOUND")
         Exit Sub
    
    End Select

    Rollin
     
  5. mrl

    mrl Thread Starter

    Joined:
    Aug 12, 2007
    Messages:
    327
    Hi Rollin, Thanks for the help. I wanted to use something that is already in my macro's that I could build on. A great way to learn ! I'm going to look at "data validation" and try to do the same thing that way. I like the idea of "mistake proof"
    Have a Happy New year


    Mike
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/971438

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice