+ 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
    2,070

    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, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  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
    2,070

    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 Expert 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,749

    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,113

    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,113

    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 Expert 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,749

    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,113

    Re: VBA Works Only On The First Time

    Clever jaslake!!!

  10. #10
    Forum Expert 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,749

    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, England
    MS-Off Ver
    365
    Posts
    15,078

    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, England
    MS-Off Ver
    365
    Posts
    15,078

    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)

Similar Threads

  1. [SOLVED] VBA Looks like it works, but it gives me Run-Time Error
    By OpieWinston in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2017, 04:07 PM
  2. Macro only works the first time
    By SCLisi in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-29-2016, 02:30 PM
  3. [SOLVED] Code works the 1st time, but not the 2nd time
    By luizmachado in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2016, 11:47 AM
  4. [SOLVED] VBA works 1st time, crashes the next
    By tejay in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2015, 03:33 AM
  5. VBA Excel Borders linestyle - works first time - not second time
    By RxMiller in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-11-2014, 12:51 PM
  6. =IF only works the first time
    By Agent007 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-09-2013, 09:29 PM
  7. Works every second time
    By hih in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2006, 02:10 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