+ Reply to Thread
Results 1 to 5 of 5

Search dynamic selection and delete cell string

  1. #1
    Registered User
    Join Date
    04-01-2007
    Posts
    12

    Search dynamic selection and delete cell string

    Hi I have a loop macro that doesn't work fully.
    If I dont get one or two empty cells at the end of the selection I get:
    Object variable or With block variable not set (Error 91).
    It loops ok, but I know the exit loop is flawed, it should loop through each cell in the range and stop.

    Here is the macro:

    Sub DeletePercent()
    '
    ' Macro 02/04/2007
    '
    Dim LastRow As Long

    LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("J2:J" & LastRow).Select
    Do Until IsEmpty(ActiveCell) And IsEmpty(ActiveCell.Offset(1, 0))
    Selection.Find(What:="%", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate

    ActiveCell.Value = ""

    Loop

    End Sub

    The data looks like:

    Arrangement £1999,
    Arrangement 1.50% Advance,
    Arrangement £1999,
    Arrangement £1999,
    Arrangement 1.50% Advance,
    Arrangement 1.50% Advance,
    Arrangement 2.50% Advance (Min £599.00),
    Arrangement 2.00% Advance (Min £599.00),
    Arrangement 1.50% Advance (Min £599.00),
    Arrangement £599,
    Arrangement 1.50% Advance (Min £599.00),
    Arrangement £599,
    Arrangement 1.50% Advance (Min £599.00),
    Arrangement £599,
    Arrangement £599,
    Arrangement 0.75% Advance (Min £599.00),


    I want to get rid of the % data, thats it.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    It will never stop because the Find changes ActiveCell to a cell that is not empty.

    Please Login or Register  to view this content.
    will loop until nothing is found.

    EDIT: BIG OOPS That should be UNTIL Err<>0 or WHILE Err=0
    Last edited by mikerickson; 04-10-2007 at 08:12 PM.

  3. #3
    Registered User
    Join Date
    04-01-2007
    Posts
    12
    Thanks mikerickson for your reply.
    I tried your code, but I couldn't get it to loop?
    Any thaughts?

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    My main thought is that I avoid using Select and Active Cell or Sheet when coding.
    This worked for me. Assuming that your example is the text that was in the column. If the percentages are numeric entrys with formatting, you will need a different kind of loop.
    You may have to put in the proper sheet name. Also note the change in search terms; What:= a wildcard, LookIn:=Values rather than formulas, After:=specific cell rather than ActiveCell.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-01-2007
    Posts
    12

    Thanks

    Thanks mikerickson, this is perfect.
    My loop theory is a little lacking at the moment, so this was a big help!

+ 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