+ Reply to Thread
Results 1 to 14 of 14

VBA Works Only On The First Time

  1. #1
    Registered User
    Join Date
    02-23-2019
    Location
    Saudi Arabia
    MS-Off Ver
    2007
    Posts
    4

    VBA Works Only On The First Time

    Hey all, I'm new to this forum and I need your help please, I'm trying to make a Quote System for my projects/clients. I have an Excel sheet with VBA code, the code is to automatically add a row on a table with clients data if I entered a new client value to a table in a different sheet.

    The weird thing is that the code works fine to add a new row and fill it with the needed data, but only for the first time, when I run it again it populate inly the first cell, and when I run it again it gives me error 400.

    Please Login or Register  to view this content.
    Please help me! the excel sheet is available to download in the attachments for a better view.

    thanks in advance
    Attached Files Attached Files
    Last edited by Emadu; 02-24-2019 at 10:55 AM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    1,722

    Re: VBA Works Only On The First Time

    Try this

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, click the 'Go Advanced' button, Then click 'Manage Attachements' and follow the menu.
    Thinking I am smart and knowing I am smart are two entirely different levels of schizophrenia.

  3. #3
    Registered User
    Join Date
    02-23-2019
    Location
    Saudi Arabia
    MS-Off Ver
    2007
    Posts
    4

    Re: VBA Works Only On The First Time

    Thanks for the reply, the code works good, but I'm still getting the same behavior.

    The weird thing is that the code works fine to add a new row and fill it with the needed data, but only for the first time, when I run it again it populate inly the first cell, and when I run it again it gives me error 400.
    Thanks a lot.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    1,722

    Re: VBA Works Only On The First Time

    I cannot duplicate the condition. The code repeats as expected for me. It could be other event code or formulas in your file that are causing the condition.
    Regards, JLG
    Last edited by JLGWhiz; 02-23-2019 at 04:44 PM.

  5. #5
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,748

    Re: VBA Works Only On The First Time

    Hi Emadu
    Welcome to the Forum!!!
    • Open your Workbook
    • Select "QuotationsDB" worksheet
    • Keyboard Ctrl+End

    You'll see this in Cell 1048575 Column I...delete it...Code works fine...

    2019-02-23_17-58-44.jpg
    Attached Files Attached Files
    Last edited by jaslake; 02-23-2019 at 07:10 PM. Reason: Add attachment
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,069

    Re: VBA Works Only On The First Time

    @ jaslake,

    You make me sick!

    How the heck, did you come up with that?

    Excellent catch, Buddy!

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,069

    Re: VBA Works Only On The First Time

    @ JLGWhiz,

    Come on now. jaslake deserves a Rep tap from you as well my friend!

    You were also correct with stating that there must be a problem somewhere else.

    Regards.

  8. #8
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,748

    Re: VBA Works Only On The First Time

    Thank you Winon...appreciate the Kudos...

    Moved the Code to a Public Module so I could see the Error Code/Description...must have been something messing it up...couldn't find the last row...why not???
    Gotta admit...took me a bit...didn't make sense...

    2019-02-23_18-38-14.jpg

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,069

    Re: VBA Works Only On The First Time

    Clever jaslake!!!

  10. #10
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,748

    Re: VBA Works Only On The First Time

    @Winon
    Thanks for the support....School's still out...the OP will be telling us...Solved???...or not???

  11. #11
    Registered User
    Join Date
    02-23-2019
    Location
    Saudi Arabia
    MS-Off Ver
    2007
    Posts
    4

    Re: VBA Works Only On The First Time

    WOW, thats weird, I wonder how did this happen.

    Thanks a ton sir, I removed the contents, now the code is not crashing. But, still it populates the correct values only the first time.
    Explain:
    - when I press the Save Quote button it should add a row to the QuotationDB table with the values of K4 to K6.
    - what happens now is: when I press the button the first time it will fill all the fields correctly, but after that it'll only fill the first cell of the table.

    Thanks again :D

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    6,143

    Re: VBA Works Only On The First Time

    How about
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-23-2019
    Location
    Saudi Arabia
    MS-Off Ver
    2007
    Posts
    4

    Re: VBA Works Only On The First Time

    Thanks a lot sir :D
    it's working fine now.

    Thank you all, you're the best.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham
    MS-Off Ver
    365
    Posts
    6,143

    Re: VBA Works Only On The First Time

    You're welcome & thanks for the feedback

+ 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