+ Reply to Thread
Results 1 to 7 of 7

Writing values from forms to sheet

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Question Writing values from forms to sheet

    Hi,

    I'm fairly new to using VBA and have a problem writing back values from a form to a worksheet. Here's what I've done

    When the form initializes this occurs

    Dim MyRange as range
    Set MyRange = Sheets ("Sheet1").Range ("A1")
    I have a control on the form which, when updated, I'd like to store the value in the above range therefore within the controls subprocedure I have

    Private MyControl_Afterupdate()

    MyRange = MyControl.Value

    End Sub
    When I enter a value in the form I don't get any error messages but I'm also not getting the value stored in the worksheet. Any help would be appreciated

    Many thanks

    Mike
    Last edited by Mike_e; 10-12-2011 at 05:43 AM.

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

    Re: Writing values from forms to sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Writing values from forms to sheet

    hi, Mike, try to put it this way:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Writing values from forms to sheet

    Many thanks for your speedy response Watersev. I've amended the code as suggested but this doesn't work. I get the "runtime error" 424 Object Required message when I change the contents of the control.

    the only way I 've been able to get this working so far is to put the following into the controls procedure

    Please Login or Register  to view this content.
    I would have thought that once I'd declared the range when the form initializes, I shouldn't need to do it again.

    Many thanks again

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Writing values from forms to sheet

    Note the .Value

    Please Login or Register  to view this content.
    Although this could be shortened to:
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Writing values from forms to sheet

    Just re-read your code, your range declaration
    Please Login or Register  to view this content.
    Should be above all your subs/functions, right at the top of the page.

    Also use option Explicit at the top of the page, this will show up any of these errors

  7. #7
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Writing values from forms to sheet

    Many thanks guys. Changing the order of my code worked fine. Live and learn

+ 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