+ Reply to Thread
Results 1 to 8 of 8

TextBox to display value in existing cell then update it

  1. #1
    Registered User
    Join Date
    07-13-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    12

    TextBox to display value in existing cell then update it

    Hello!

    I've been trying to figure this out for a couple of days- no luck. I built a UserForm that populates an Excel sheet based on some simple choices and data entry.

    First, the user must choose 2 values from 2 dropdown menus:
    1. Month
    2. Facility

    Then they are to enter 2 numbers into 2 text boxes: TextBox1 and TextBox2. These numbers are recorded on the spreadsheet in columns D and E, respectively. The target row depends on the Month and Facility selected.

    Now here's the problem: When the user initializes the UserForm, then picks Month and Facility, I'd like TextBox1 to display the current value in the corresponding D cell. The user can then choose to keep the shown value or update it then hit Enter to populate the spreadsheet.

    I'm loosing my mind over this! I feel like it's probably a very simple one-line code, but for some reason I just can't get it right!

    Thank you!
    Last edited by vceh; 07-14-2011 at 06:47 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: TextBox to display value in existing cell then update it

    Hi vceh
    Welcome to the forum.
    Upload your example for us to work on
    It will save us having to reinvent a wheel before we can address your requirement

  3. #3
    Registered User
    Join Date
    07-13-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: TextBox to display value in existing cell then update it

    Hi Barry! Thank you

    It's for work and for regulatory purposes, so I'm not sure it would be OK to upload the whole thing. Contains company-specific data. I can maybe post a snapshot of the UserForm or a section of code. Here's some of it:
    Please Login or Register  to view this content.
    Now, you can see TextBox2 defaults to 0, which is fine. I'd like for TextBox1 to default to a value within a cell, depending on the Month and Facility selected.

  4. #4
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: TextBox to display value in existing cell then update it

    vceh
    The attached bare bones idea may get you going - macro "uf".
    Select from the comboboxes and click anywhere on the user form.
    Change or accept Texbox1 and click OK to write it back.
    Basically it uses the ListIndex property of the comboboxes to identify a cell to populate Textbox1.
    You can then develop it to suit
    barry
    Attached Files Attached Files
    Last edited by barryleajo; 07-13-2011 at 05:40 PM.

  5. #5
    Registered User
    Join Date
    07-13-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: TextBox to display value in existing cell then update it

    Thanks for your help, Barry!

    I only used the UserForm_Click() section, and I keep getting this error:

    Run-time error ‘91’:
    Object variable or With block variable not set


    Can you explain it to me? I'm not sure what it's asking for here. It was giving me a different error, but when I declared ws As Worksheet within the Sub, it started giving me this one.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-13-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: TextBox to display value in existing cell then update it

    Figured it out: I should've used Set ws = Worksheets("Jan") instead of Dim ws As Worksheet. I'm new to all of this, so that explains the silly mistake.

    Thanks, again, Barry!

  7. #7
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: TextBox to display value in existing cell then update it

    Well done mate!
    Glad to be of help.
    If you are satisfied then please mark thread as Solved.

  8. #8
    Registered User
    Join Date
    09-24-2011
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: TextBox to display value in existing cell then update it

    Hi Guys ,

    I need a excel sheet where if I click on a single cell value ( Cell A1) in a range then its value should show in a msg box ... please help me ..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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