+ Reply to Thread
Results 1 to 2 of 2

Search and move macro

  1. #1
    Registered User
    Join Date
    07-16-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    1

    Search and move macro

    Hi all,

    I've been trying to write a macro for my work that

    1) searches for an erroneous cell "#N/A"
    2) copies the data from this cell
    3) looks for a string in another comulmn
    4) if it finds that string, goes to the particular row
    5) pastes the relevant data
    6) delete the whole row with the "#N/A"

    this is the code that I have come up with thus far:

    Please Login or Register  to view this content.
    My problem occurs on the line that starts with "c = Selection.Find..."

    On my first run, it threw up a "Object Variable or With Block Variable not set" every time the string i was searching for in Column D was not found.

    So I tried using some simple error handling using the On Error GoTo statement. Line 2 is the error handling process.

    The issue is that the first time the Selection.Find command fails to find the string, the On Error command works fine, and the macro moves on to the next cell. But the second time it fails to find the string, it throws up the "Object Variable or With Block Variable not set" error, even though i already have an On Error statement.

    What could be the problem?

    As you probably can tell, im a beginner and the code is just brute forcing my way down a spreadsheet. Any suggestions to make this task more elegant would be extremely welcome.

    The workbook is a bit too large to upload here, but if you need it for reference, PM me!
    Last edited by Paul; 07-16-2009 at 08:43 PM. Reason: Changed QUOTE tags to CODE tags

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Search and move macro

    Hi

    An example workbook would be helpful. Don't attach the real on, but make up one that has the same structure / format, but doens't contain any sensitive data.

    Then explain using that example file what you are trying to achieve, and if possible show a before and after view.

    rylo

+ 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