+ Reply to Thread
Results 1 to 17 of 17

Macro to skip the error and process to next VBA

  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Macro to skip the error and process to next VBA

    Hello,

    My code >

    Please Login or Register  to view this content.
    When Excel do not find "Invoice Amount, I want excel to go to Last VBA, that is Columns("B:B"). auto fit and do nothing in column B.

    Please advice
    Regards,
    Last edited by shiva_reshs; 01-31-2013 at 05:55 PM. Reason: Solved

  2. #2
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Macro to skip the error and process to next VBA

    Hi Shiva,

    Did you tried the on error goto errorhandler

    after endwith give the Errorhandler.
    Thanks!
    Raga.

    Please,mark your thread [SOLVED] if you received your answer.

    Click the little star * below, to give some Rep if you think an answer deserves it.

    I learnt so many things from these links.

  3. #3
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Macro to skip the error and process to next VBA

    Hi Shiva,

    Did you tried the on error goto errorhandler

    after endwith give the Errorhandler.

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

    Re: Macro to skip the error and process to next VBA

    Move the End If down.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Hi,

    I am not good with VBA . I just take help of this site on all my coding
    Could you please specify , where/How i need to add Error Handler please.

    Regards
    Shiva

  6. #6
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    let me check, Norie. I would reply on my findings. Thanks

  7. #7
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Hi Norie,

    It gives me a error
    Please Login or Register  to view this content.
    Error Message is "Paste Special method of Range class failed"

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

    Re: Macro to skip the error and process to next VBA

    So if the find works you want to do the copy and paste, but if not move straight onto the autofit?

    Please Login or Register  to view this content.
    By the way, this code will do the find and replace an every cell in the worksheet.
    Please Login or Register  to view this content.
    Do you not want to restrict it to a specific range?

  9. #9
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: Macro to skip the error and process to next VBA

    Try this way..

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    I am copying the value from the Pivot table and I am copying multiple tables from there.
    Give you and example, Annul turnover Pivot data. But when I run a pivot on different month's, there are cases when there is no invoice amount on a certain month. So when I run Pivot on that month, Invoice data do not show in Pivot table.

    The code which I found, gives a message box, that Invoice amount is not found, but it still goes and try to paste it in Summary - qtr sheet, giving a hard error to stop the VBA. Thats why i need something which skips it if it is not found and paste nothing in coloumn B.

    I hope that answer your question why I cant restrict to specific range.

    Now for your question on
    Please Login or Register  to view this content.
    Next to Pivot, I added some calculation. Like G7/F7-B7. When there is nothing found in G7/F7-B7 it answer to #DIV/0! and also copy #DIV/0! amount in my summary-qtr sheet. So I needed that code to remove #DIV/0! from the cell. I mistakenly typed only 0 instead of #DIV/0! while pasting the code in my question. Sorry for the confusion.

    Thanks

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

    Re: Macro to skip the error and process to next VBA

    The last code I posted (post #7) will only do the copy and paste if the find is succesful.

    If the find isn't succesful then the message box will be shown and the code will move onto the autofit.



    Why not change the formula so you don't get any #DIV/0! errors?

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Hi Raga,

    Your code did not give any error, but it still copies the earlier copied data and paste it into coloumn "B"
    I am using a repetitive code to copy the required row again and again. Please see below code.

    Please Login or Register  to view this content.
    Any workaround on this?

    Thanks

  13. #13
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Norie, I am testing your code. Will post update here.!

    Thanks

  14. #14
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Hi Norie,

    Your code worked. I dont know what I missed earlier when you posted your code on (Post # 8). Thanks for your help!
    Can you suggest the coding for to avoid getting #DIV/0 please.
    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Thanks!!!

  15. #15
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    Thanks Raga for helping this out!! I will close this thread once I receive reply from Norie.

    You guys are the best! Reps added.

    Regards
    Shiva!

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

    Re: Macro to skip the error and process to next VBA

    See my earlier post about changing the formula to avoid the #DIV/0! error.

  17. #17
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: Macro to skip the error and process to next VBA

    got it. Thanks

+ 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