+ Reply to Thread
Results 1 to 14 of 14

Stop Macro From Falling Over

  1. #1
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Stop Macro From Falling Over

    This macro works fine but falls over when it can't find a match can anyone advise how I can get around that please? I have highlighted in bold

    Thanks

    Please Login or Register  to view this content.
    Last edited by timbo1957; 10-13-2011 at 10:46 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Stop Macro From Falling Over

    You need to define a variable as a range, set the value of that variable to equal the results of the .Find operation (rather than trying to select the results directly) and then test for that variable being Nothing, e.g.

    Please Login or Register  to view this content.

    You could really do with revisiting your code - in VBA it's rarely necessary to select or activate anything, you can just tell Excel which object you're referring to - i.e.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Thanks Andrew-R,

    A great help.

  4. #4
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi Andrew-R,

    You helped me out a couple of days ago and I was wondering if you could help again today?

    I am using this code to delete all rows that don't have the letter "A" in column AN. How can I expand this to enable me to delete all rows that don't have the letter "A" or "n/a" in column AN.

    Many thanks

    Please Login or Register  to view this content.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Macro From Falling Over

    Is the data in a Table format that you can Autofilter
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi Roy,

    Yes but I have never used Autoformat in a macro.

    Basically what I am trying to do is -

    Wkbk1 if the value in column AN is "A" or "n/a" then go to the reference number in column X.
    offset that cell by one column to the left (W) and copy that value

    Switch to Wkbk2 Select column A and find the reference number from Column X in Wkbk1
    when the macro finds the ref no paste the copied cell offset 2 cells to the right

    The macro does that okay but I have the anomaly of what to do if the ref number in wkbk1 doesn't exist in wkbk2 - I'd like it copied to the bottom of the data in row A.

    Any help appreciated.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Macro From Falling Over

    Try recording a macro, then it can be edited

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi Roy,

    This works down to the bit in bold where it needs adapting to allow rows containging "n/a" to remain and not be deleted.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Stop Macro From Falling Over

    Please Login or Register  to view this content.



  10. #10
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi snb,

    Can you explain where I should put this in the current macro and how it works please?

    Thanks

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Stop Macro From Falling Over

    It's a replacement of your whole macro........
    If you try to understand the code, you'll see why & how it works.

  12. #12
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi snb,

    I have pasted it in and stepped it through but it deletes all the information I am trying to keep.

    The information is in column 40 so I have made that adjustment and I want to keep all rows with either "A" or "n/a".

    Please Login or Register  to view this content.
    Can you advise please?

    Thanks

    Tim.

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Macro From Falling Over

    Attach a dummy workbook

  14. #14
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro 2003 / 2010
    Posts
    423

    Re: Stop Macro From Falling Over

    Hi Roy,

    I have cut out all of the info except column AN where I want to delete all rows except those with either "A" or "n/a".

    Tim.
    Attached Files Attached Files

+ 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