+ Reply to Thread
Results 1 to 16 of 16

CommandBox Code to update a selected WorkSheet from a UserForm

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    CommandBox Code to update a selected WorkSheet from a UserForm

    Hi,
    I have created a logging system using excel and would like to take it one step further. I have been reading about UserForms in excel so I’m very much the novice here, but it’s what I want to do to improve the usability for the excel workbook.
    The Wookbook contains 21 worksheets, each worksheet being a different site, the UserForm has a series of Comboboxes and textboxes, The first Combobox contains all the worksheet names using the below code:

    Please Login or Register  to view this content.
    The remaining comboboxes pull data from a worksheet called data. What I'm after is the code for a CommandBox that will populate the selected Worksheet from the UserForm and all the other data that has been populated using the other ComboBoxes and TextBoxes. I will also require it to find the next available row so it is not over writing the previous data that’s been added.
    Can you please help I have tried other code, from other internet sources, but can't seem to get this working.
    Cheers
    Last edited by NickR1; 12-31-2012 at 07:21 AM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Hi NickR1,

    Welcome to the Forum.

    When reading the Forum Rules, perhaps you overlooked the one that requires the use of code tags?
    Before receiving any help, which we're all glad to give, edit your post to add the missing code tags.

    Simply hightlight all lines of VBA code then press the button with the # symbol on it.

    Thanks.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    HI Palmetto,

    Sorry about that, I've added the code tags.

    Cheers

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Here is the basic code example -- see if you can build off this.

    Please Login or Register  to view this content.
    You may find this useful: Userforms & Controls
    Last edited by Palmetto; 12-31-2012 at 08:30 AM.

  5. #5
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Thank You! I will try and adopt this to my UserForm. I will let you know how I get on.

    Thanks.........

  6. #6
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Hi Palmetto,

    I have adopted the code you provided to the UserForm I created and adding the data I selected from the Userform to the worksheet that is also select in the UserForm works. Here is the code I amended to what you gave me.

    Please Login or Register  to view this content.
    I am experiencing an issue though!

    One each of the Worksheets in the workbook I have added data validation to 500 rows each cell in the row using data validation but different values, so I can select options like Call Open, Call Closed in one cell and call type like Phone Call, e-mail in another etc. The data validation pulls the data from a separate Worksheet call Data (This is the same for the UserForm comboboxes).

    When I select the required data from the UserForm and use the CommandButton Click it populates the Worksheet but it adds the data to the next row \ cells that don't have the data validation configured, so it adds the data to row 501 even though row 2 cells are still blank, and this is where I want the data added, as I haven't populate them with the data validation data.

    Is there a way to use the UserForm to populate the Data to the worksheet row \ cells but still have the option to select the values from the data validation on the worksheet when I need to change them?
    Last edited by NickR1; 01-04-2013 at 08:24 AM.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    To to find nextrow use a column that doesn't have data validation.
    If posting code please use code tags, see here.

  8. #8
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Is there a way to use the UserForm to populate the Data to the worksheet row \ cells but still have the option to select the values from the data validation on the worksheet when I need to change them?
    Writing values to a cell using VBA does not alter the data validation. If the cell already has DV applied it will still function correctly after writing a value to it. I may not be clear about what you want. If so, try to be more explicit about what you are trying to accomplish.

  9. #9
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Thanks Palmetto,m, humm that's strange.......can you advise why the userform is adding the data to row 501 and not row 2, is this because there is DV added to the cells in row 1 through to 500?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    NickR1

    Have you tried using another column to find the next row?

  11. #11
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Hi Norie,

    Not following when you mean say “use another column to find the next row”...sorry if I'm being a bit thick...:-(

    I have cleared the formatting from column A row 2, thinking because I had a comment in it however when I click the command button it still adds the data select in the userform to row 501, even though there is no data added to any of the cells from column A through to I and row 2 through to 500.

    What do you think this is happening is there something I have got wrong in the code?

    Please Login or Register  to view this content.
    Last edited by NickR1; 01-06-2013 at 04:06 PM. Reason: typo

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    I just mean that instead of looking in column A to find the next row look in another column.

    For example to look in column B.
    Please Login or Register  to view this content.
    If that doesn't help it might be an idea to attach a workbook.

  13. #13
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Hi Norie,


    Your suggestion of finding another column (Column J) has enabled it to update the next blank row, however if I use the userform again it overwrites the same row instead of updating the next blank row. I have amended it so the first row is row 4.

    Please Login or Register  to view this content.
    Any ideas?

    Thanks

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Attach a workbook?

  15. #15
    Registered User
    Join Date
    12-21-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: CommandBox Code to update a selected WorkSheet from a UserForm

    Hi Norie,

    I will attach the workbook but I will have to reduce the size as its 18MB, I'm out on the road working so I will do this before the end of the week. One other question, how will I attach it other than insert an image??, I can't see an option to attach a file anywhere.

    Thanks in advance

    Cheers

    Nick

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Click Go Advanced, click the paperclip in the toolbar and you'll get a dialog where you can select a file to attach/upload.

+ 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