+ Reply to Thread
Results 1 to 11 of 11

VBA glitch on User Form

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    VBA glitch on User Form

    Hi,

    Firstly I'm a complete VBA newbie so bear with me!

    I'm exploring and learning about user forms and I've cracked the basics. However, the problem is that whenever I input data via the user form, it replaces what was input before.

    So my VBA for a command button to capture the data is this.....

    Private Sub cmdSave_Click()
    erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Cells(erow, 1) = DatePick
    Cells(erow, 2) = CheckBox1.Value
    Cells(erow, 3) = cmbActivity.Text
    Cells(erow, 4) = tbDuration.Text
    Cells(erow, 5) = tbMileage
    Cells(erow, 6) = tbLogDetails.Text
    End Sub

    When I run the form for the first time it places the captured data on row 2 in Sheet1 as it should under the correct headings in row 1. However, if I then submit some new data via the user form, the data in row 2 is replaced with the newly submited data. In fact every time the user form is run, it just replaces what's on row 2 of Sheet1 with new data. Where am I going wrong?

    Many thanks.

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

    Re: VBA glitch on User Form

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: VBA glitch on User Form

    try this modification

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: VBA glitch on User Form

    Example file attached. Many thanks.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: VBA glitch on User Form

    Thanks Andy but this returns an error

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: VBA glitch on User Form

    I think you are confusing sheet tab text with sheet code name.

    Please Login or Register  to view this content.
    sheet tab name 'Sheet1' is in fact code name Sheet5

    so basically the end row as being determined from the row sheet and output was to the activesheet when I think you wanted adding to the log on 'Sheet1'

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

    Re: VBA glitch on User Form

    Sheet1 is actually the codename for the 'SUMMARY', so that's what your code is referring to when finding the next empty row.

    If you want the data to goto the sheet with the tab name 'Sheet1' and codename Sheet5 try this.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: VBA glitch on User Form

    Works perfectly!

    Thank you so much, Norie.

  9. #9
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: VBA glitch on User Form

    Norie,

    Just a quick aside - the line

    .Cells(erow, 4) = tbDuration.Text

    what do I need to change '.text' to to ensure the data is captured as a number?

    Many thanks

  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: VBA glitch on User Form

    It's coming out as a number, specifically a time, on the worksheet when I try it.

    Mind you the value from tbMileage is flagged as 'Number stored as Text' when transferred to the sheet.

    If you want to ensure both go to the sheet properly as numeric data try this.
    Please Login or Register  to view this content.
    PS Can you add code tags when posting code?

  11. #11
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: VBA glitch on User Form

    Thank you Norie

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how can i give a link to one user form to anther user form
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2014, 07:37 PM
  2. [SOLVED] User Form to execute search and return all values to the user form for editing
    By allwrighty in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2013, 10:40 PM
  3. [SOLVED] Excel vba user form- open directly to user form not worksheet
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 04-24-2013, 05:07 PM
  4. [SOLVED] Excel user form- If/Then statement outcome to show on user form
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2013, 09:16 AM
  5. Print preview from user form opened from a user form
    By Brunstgnegg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2011, 05:12 AM

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