+ Reply to Thread
Results 1 to 10 of 10

Data not showing up in worksheet when hitting save(add) button when runnin macro

  1. #1
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Data not showing up in worksheet when hitting save(add) button when runnin macro

    Hello, first time here and new to VB. Ok here is what I have, Have form with labels, text box and command button. When I hit the save button after entering data it does not enter it into worksheet and I do not get any error messages as to saying the code is not working. Have 3 text boxes and labels, 2 command buttons, 1 for saving and 1 for exiting. What I am trying to do is enter data into worksheet, save it and next time it enters in next row and so forth.

    Thanks, Mike

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Hi Mike

    The code is not broken - it just is not doing what you want it to do.
    Please post your workbook by clicking on Reply, then GOAdvanced, then look below for ManageAttachments etc
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Sorry, am not sure what info you want from the file? Not sure how to post workbook.

    Private Sub cmdSave_Click()
    Dim lRow As Long
    Dim WS As Worksheet
    Set WS = Sheet1
    lRow = WS.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    'Add data to worksheet
    WS.Cells(lRow, "A") = Me.txtDate.Value
    WS.Cells(lRow, "B") = Me.txtTailNumber.Value
    WS.Cells(lRow, "C") = Me.txtGallonsSold.Value
    'Clear userform
    txtDate.Value = vbNullString
    txtTailNumber.Value = vbNullString
    txtGallonsSold.Value = vbNullString
    txtGallonsSold.SetFocus

    End Sub

  4. #4
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    uploaded file
    Attached Files Attached Files

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Since you have hardcoded the Sheetname this will only work in sheet January.
    Try example file. It puts the data in corresponding sheet depending on month you put in txtDate-textbox.
    Attached Files Attached Files
    Last edited by bakerman2; 04-03-2016 at 10:00 PM.

  6. #6
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Works great, but I accidentally put in wrong date and got run-time error. Is there a way to code date as to if it is not entered as MM/DD/YY, message pops up as invalid date?

    Thanks, Mike

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Add this to Userfom codemodule.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Thought I had it, Now when I do put the right format in I still get message? After message clears data how do I get cursor to go back to date text box, tried to set date as focus but did not work. And how do you make sure box is not left empty? Ex. date has to be put in before continuing?

    Private Sub txtDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    txtDate.Text = Format(txtDate.Text, "mm/dd/yy")
    If txtDate.Text <> Format(txtDate.Text, "mm/dd/yy") Then
    Else
    Call MsgBox(" Invalid Date or Fomat")
    txtDate.Text = ""
    End If
    'If txtDate.Text = "" Then
    'txtDate.SetFocus
    'End If
    End Sub
    Attached Files Attached Files
    Last edited by Mik10; 04-04-2016 at 08:52 PM.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    How about this one, with a calendar to select date.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    04-03-2016
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    10

    Re: Data not showing up in worksheet when hitting save(add) button when runnin macro

    Yes it works, but still would like to know how to code if date is not in dd/mm/yy format or no date or wrong format, ex.(36456064)? Which with last entry (36456064) returning an run-time error.

+ 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. When clicking macro button back data is not showing
    By AB95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2014, 12:15 PM
  2. Click activated button upon hitting Enter.
    By ajaykgarg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2013, 01:01 AM
  3. [SOLVED] Inserting data into the next row when hitting the submit button
    By jamalfried in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-01-2013, 05:05 PM
  4. Macro Button to copy data from one worksheet to second worksheet with criteria
    By vortex1fire in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2013, 06:24 PM
  5. [SOLVED] How to: copy data from sheet 1 to 2 after hitting a submit button?
    By WillGe in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-12-2012, 01:29 AM
  6. Hitting return key, linked to a button
    By ebaynut in forum Excel General
    Replies: 2
    Last Post: 10-02-2011, 01:00 PM
  7. [SOLVED] Have to keep hitting the Continue Button
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-23-2006, 07:45 PM

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