+ Reply to Thread
Results 1 to 3 of 3

delete entire row when value is found

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2015
    Location
    Milan
    MS-Off Ver
    2013
    Posts
    110

    delete entire row when value is found

    dear all,

    below part of my code inside a user form .
    I am trying ,once the value is found to delete the entire row but no success (get an error on the line "hawb2.entirerow.delete").
    can someone help ?

    dim hawb2 As Range
    Dim answer As Integer
    test1 = TextBox2.Value
    wk = ActiveWorkbook.Name
     
        Set hawb2 = ActiveSheet.Range("b:b").Find(What:=test1, LookIn:=xlFormulas, LookAt:=xlWhole)
    
         If Not hawb2 Is Nothing Then
         answer = MsgBox("awb already exist in " & wk & " row " & hawb2.Row & vbNewLine & "would you like to delete it ?", vbYesNo + vbQuestion)
         If answer = vbYes Then
         hawb2.EntireRow.Delete
    
         MsgBox "AWB DELETED"
         Exit Sub
         End If
         If answer = vbNo Then
         Exit Sub
         End If
         
         End If

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,355

    Re: delete entire row when value is found

    Hi Lorenzo,

    "EntireRow.Delete" is supposed to come after a range (or a cell) in most cases. See: https://msdn.microsoft.com/en-us/lib.../ff836836.aspx

    How about something like this to do the job?

    Sub DelRowTest1()
        Dim LastBRow As Double
        Dim RowCtr As Double
        
        LastBRow = Cells(Rows.Count, "B").End(xlUp).Row
        
        For RowCtr = LastBRow To 1 Step -1
            If Cells(RowCtr, "B").Text = "test1" Then
                Cells(RowCtr, "B").EntireRow.Delete
            End If
        Next RowCtr
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    02-14-2015
    Location
    Milan
    MS-Off Ver
    2013
    Posts
    110

    Re: delete entire row when value is found

    Dear MArvin,

    tks so much for your suggestion..f.y.I my code works..problem was the fact that I do not realized sheet was protected and this is why I got the error....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete Entire Row if Blank is Found in Column
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-17-2014, 11:28 PM
  2. Replies: 3
    Last Post: 03-04-2014, 04:55 AM
  3. delete the entire row if duplicate found in column
    By gujugolf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2013, 04:07 PM
  4. [SOLVED] If Or statement to check cell text and delete entire row if text is found
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 11:46 AM
  5. [SOLVED] Macro To Delete Entire Row If Dublicate Is Found
    By SilverFox in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-07-2012, 06:07 AM
  6. delete entire row if 'value' found anywhere in column - most efficient way?
    By intothewild in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-25-2012, 08:21 AM
  7. Replies: 6
    Last Post: 05-24-2012, 09:14 AM

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