+ Reply to Thread
Results 1 to 4 of 4

Thread: Macro to delete rows upto a certain cell input value

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    texas
    MS-Off Ver
    Excel 2011
    Posts
    10

    Macro to delete rows upto a certain cell input value

    Hi,

    I am looking for a macro to delete all rows from A1 upto and including a row containing -- Raw Data -- in column A. Any help on this would be greatly appreciated. thanks
    Last edited by jhmayor03; 02-02-2012 at 11:26 AM. Reason: solved

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,399

    Re: Macro to delete rows upto a certain cell input value

    Use this code -
    Option Explicit
    Dim lrow As Long
    Dim i As Long
    
    Sub del_rows()
    
    lrow = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To lrow
        If Range("A" & i).Value = "Raw Data" Then
            Rows(1 & ":" & i).Delete
            Exit For
        End If
    Next i
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Macro to delete rows upto a certain cell input value

    hi jhmayor03, try sort of that:

    Sub test()
    
    Dim last_range As Range
    
    Set last_cell = Range("a1", Cells(Rows.Count, "a").End(xlUp)).Find("-- Raw1 Data --", , xlValues, xlWhole)
    
    If Not last_cell Is Nothing Then
        
        Application.ScreenUpdating = 0
    
        Range("a1", last_cell).EntireRow.Delete
    
        Application.ScreenUpdating = 1
        
    End If
    
    
    End Sub

  4. #4
    Registered User
    Join Date
    02-01-2012
    Location
    texas
    MS-Off Ver
    Excel 2011
    Posts
    10

    Re: Macro to delete rows upto a certain cell input value

    Thank You works perfectly!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0