+ Reply to Thread
Results 1 to 6 of 6

Trying to add input box to code and use value in a counter

  1. #1
    Registered User
    Join Date
    09-24-2010
    Location
    Illinois, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Trying to add input box to code and use value in a counter

    The following code in Outside Storage2 works fine:

    Please Login or Register  to view this content.
    I tried to add an input box and use the value entered in a counter, but the code does not work. This is the code in Outside Storage3:

    Please Login or Register  to view this content.
    I want the input box to open upon the opening of the spreadsheet, but it doesn't. If I enter a value in C1, then the input box opens. But then I can't get the input box to close. It results in an endless loop.

    I have attached both spreadsheets. Any help will be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Trying to add input box to code and use value in a counter

    I want the input box to open upon the opening of the spreadsheet
    If thats the case then you need to put your inputbox in the Worksheet_Activate event .

    Worksheet_Change is fired when a value in a cell is changed. Your also going to want to become familiar with Application.EnableEvents = False and Application.EnableEvents = True Without these your going to end up in infinite loops in your Change events. In other words you add a value in you "Change Event " which triggers a change event ... which triggers a change event .... and on and on ... but Application.EnableEvents = False[/B] will turn the repeat of the trigger . See how I used it in my code .

    Please Login or Register  to view this content.
    Last edited by nimrod; 03-31-2011 at 11:51 PM.

  3. #3
    Registered User
    Join Date
    09-24-2010
    Location
    Illinois, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Trying to add input box to code and use value in a counter

    I tried the code, but the input box doesn't open now. Should the Worksheet_Activate Event be on Sheet 1?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Trying to add input box to code and use value in a counter

    You place the code into the sheet module of the relevant sheet

    Worksheet event code is stored on a worksheet module. To add it to your worksheet, do the following:

    Copy the code
    Select the worksheet in which you the code to run
    Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
    Where the cursor is flashing, choose Edit | Paste
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trying to add input box to code and use value in a counter

    Hi sbernard
    I'm trying to understand why you want to enter the number of Pallets in Cell E2. What's the overall objective...what's the value used for?

    This code
    Please Login or Register  to view this content.
    will fire 1 time or 100 times, depending on how many entries the user makes in column 1 and column 2...how does that relate to the value in E2...what's it used for?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Trying to add input box to code and use value in a counter

    Also, you don't need to activate/ select the ranges

    After your code selects C1, then the Target column must be 3, & the target column must be 2, so why check? Then your code checks again. Why is it activating those cells?

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1