+ Reply to Thread
Results 1 to 5 of 5

Delete on Search macro needs to run on used range of column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Delete on Search macro needs to run on used range of column

    Hi All,

    I have a code which works fine , but i have a issue when i want to delete rows 5000 or more the macro takes lot of time to run . I need that macro starts from line to as mention below and go till used range of the column and then delete the row according to given column c?

    Sub deleteOnSearch()
    J = 2

    For i = 2 To 5000 'give the no of rows to search for

    Range("C" & J).Select 'give here the column to search in

    If ((ActiveCell.Value() = "0")) Then 'give here the search string

    Rows(J & ":" & J).Select

    Selection.Delete Shift:=xlUp

    J = J - 1

    End If

    J = J + 1

    Next

    End Sub


    Cheers

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Delete on Search macro needs to run on used range of column

    Do you have any blank rows in your data?

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: Delete on Search macro needs to run on used range of column

    Yes i have the blank row in data as well i need to remove blank row based on column C as well.


    Cheers

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Delete on Search macro needs to run on used range of column

    This might be quicker:
    Sub deleteOnSearch()
    
    Dim i As Long, r As Range
    
    Application.ScreenUpdating = False
    
    For i = 2 To Range("A" & Rows.Count).End(xlUp).Row 'give the no of rows to search for
        If Range("C" & i).Value = 0 Then 'give here the search string
            If r Is Nothing Then
                Set r = Range("C" & i)
            Else
                Set r = Union(r, Range("C" & i))
            End If
        End If
    Next i
    
    r.EntireRow.Delete shift:=xlUp
    
    Application.ScreenUpdating = True
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: Delete on Search macro needs to run on used range of column

    HI StephenR.

    Forum Guru :-) That is working perfectly... Much Much quicker ...

    Cheers
    Farrukh

+ 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