+ Reply to Thread
Results 1 to 16 of 16

VBA Code is not Entering UserForm Values on Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    VBA Code is not Entering UserForm Values on Worksheet

    So here is the skinny... I've created a userform to enter data into my sheets. The code should look for the last open cell in the given range and add the data to it. The only thing is, its not working. No errors now, its just not entering the data.

    Private Sub btnOkay_Click()
    Dim LastRow As Long
    
    'Adds 1 to get to the Row following the last populated Row
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    Worksheets("2014").Range("D1" & LastRow).Value = tbNetSales.Value
    Worksheets("2014").Range("G1" & LastRow).Value = tbDiscounts.Value
    Worksheets("2014").Range("p1" & LastRow).Value = tbCreditCards.Value
    
    End Sub
    Any suggestions?
    Last edited by drsadistic; 08-07-2014 at 01:22 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA Code not working

    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value etc
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code not working

    Quote Originally Posted by nathansav View Post
    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value etc
    Thank you nathansav for your help. I've fixed my code per your advice, and now I am receiving this error:

    Application-defined or object-defined error

    Did I forget to define something?

    Here is my updated code:
    Private Sub btnOkay_Click()
    Dim LastRow As Long
    
    'Adds 1 to get to the Row following the last populated Row
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value
    Worksheets("2014").Range("G" & LastRow).Value = tbDiscounts.Value
    Worksheets("2014").Range("P" & LastRow).Value = tbCreditCards.Value
    
    End Sub

  4. #4
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code not working

    Quote Originally Posted by drsadistic View Post
    Thank you nathansav for your help. I've fixed my code per your advice, and now I am receiving this error:

    Application-defined or object-defined error

    Did I forget to define something?

    Here is my updated code:
    Private Sub btnOkay_Click()
    Dim LastRow As Long
    
    'Adds 1 to get to the Row following the last populated Row
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value
    Worksheets("2014").Range("G" & LastRow).Value = tbDiscounts.Value
    Worksheets("2014").Range("P" & LastRow).Value = tbCreditCards.Value
    
    End Sub
    Anyone with any ideas?

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: VBA Code not working

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code not working

    Quote Originally Posted by FDibbins View Post
    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Fixed, sorry about that.

  7. #7
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA Code is not Entering UserForm Values on Worksheet

    What is the valie of lastrow, does the worksheet 2014 exist, what is tbNetSales.value, where is the error !!!

    you need to detail where errors are etc, we cant see your screen.

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

    Re: VBA Code is not Entering UserForm Values on Worksheet

    What's the current code?
    If posting code please use code tags, see here.

  9. #9
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code is not Entering UserForm Values on Worksheet

    Private Sub btnOkay_Click()
    Dim LastRow As Long
    
    'Adds 1 to get to the Row following the last populated Row
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value
    Worksheets("2014").Range("G" & LastRow).Value = tbDiscounts.Value
    Worksheets("2014").Range("P" & LastRow).Value = tbCreditCards.Value
    
    End Sub
    This is my most current code.

    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value
    This is the line that presents the error. The error is
    Application-defined or object-defined error.

  10. #10
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: VBA Code is not Entering UserForm Values on Worksheet

    Best way to attache sample workbook.
    Regards,
    Nandkumar S.
    ---------------------------------------------------------------
    Don't forget to Click on * if you like my solution.

  11. #11
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code is not Entering UserForm Values on Worksheet

    Here's the problem, I'd rather not post my workbook online... I own restaurants and the sales information is sensitive. I'd be willing to open a line for Teamviewer if anyone would be open for remotely looking at my code.

  12. #12
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: VBA Code is not Entering UserForm Values on Worksheet

    try changing line

    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    to
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
    or
    LastRow = Worksheets("2014").Range("a65536").End(xlUp).Row + 1

  13. #13
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code is not Entering UserForm Values on Worksheet

    I changed the line per your instructions, and they both fixed the error... however neither of them inserted the value I designated in the Texbox into the appropriate cells. Nothing happened, in fact. Here is my newest code:

    Private Sub btnOkay_Click()
    Dim LastRow As Long
    
    'Adds 1 to get to the Row following the last populated Row
    LastRow = Worksheets("2014").Cells(Rows.Count, 1).End(xlUp).Row + 1
    Worksheets("2014").Range("D" & LastRow).Value = tbNetSales.Value
    Worksheets("2014").Range("G" & LastRow).Value = tbDiscounts.Value
    Worksheets("2014").Range("P" & LastRow).Value = tbCreditCards.Value
    
    End Sub

  14. #14
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA Code is not Entering UserForm Values on Worksheet

    You need to attach a sample, code means nothing without the data its working on.

  15. #15
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code is not Entering UserForm Values on Worksheet

    Can I send it to one of you via email or PM?

  16. #16
    Registered User
    Join Date
    06-15-2014
    Location
    Cuthbert, Ga
    MS-Off Ver
    Office 2013
    Posts
    64

    Re: VBA Code is not Entering UserForm Values on Worksheet

    Okay, I fixed this particular issue myself... thank you to everyone who offered advice.

+ 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. [SOLVED] Vba code working in workbook module but not working from personal.xlb
    By satputenandkumar0 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-19-2014, 05:47 AM
  2. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  3. Removing code line stops code working?!?!?
    By adamj1910 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2012, 02:36 PM
  4. [SOLVED] VBA Code (colums to row, autofill) stop working in row 294 when new cable code appear
    By sknifseht in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2012, 05:27 AM
  5. Code for email alerts from excel isn't working, wrong code possibly?
    By jessthorogood in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 01:45 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