+ Reply to Thread
Results 1 to 5 of 5

Find string in specific column of active selected row...

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2016
    Location
    Chicago
    MS-Off Ver
    2007
    Posts
    7

    Find string in specific column of active selected row...

    Hi all. New on here. Trying to get some basic programming done on an invoice template I'm working on for my job.
    Feel pretty stupid but I'm also newer to programming so that will explain my lack of knowledge of the language. Here's my problem..

    I have a button to delete an entire row if not needed. I have in column U text that simply says "OK"
    I would like to delete the entire selected row when I click the button as long as column U doesn't say "OK".

    I can't figure out what the syntax should be in vba.

    I have this which obviously doesn't work:

    Sub Button8_Click() 'Delete

    If Application.CountA(ActiveCell.EntireRow) And Columns("U:U") = "OK" Then 'My problem line!

    ActiveCell.Offset(0, 1).EntireRow.Delete
    End If

    End Sub

    Any help would be great. Thanks!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,855

    Re: Find string in specific column of active selected row...

    Try:
    Sub Button8_Click()
        Application.ScreenUpdating = False
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Range("U1:U" & LastRow).AutoFilter Field:=1, Criteria1:="<>OK"
        Range("U2:U" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
        Application.ScreenUpdating = True
    End Sub
    This macro assumes you have headers in row 1 and your data starts in row 2. It deletes all rows that don't have "OK" in column U.
    Last edited by Mumps1; 11-17-2016 at 02:22 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Find string in specific column of active selected row...

    
    Sub Button8_Click() 'Delete
    
    If Range("U" & activecell.row).value <> "OK" Then ActiveCell.EntireRow.Delete
    
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Find string in specific column of active selected row...

    
    Sub Button8_Click() 'Delete
    
    If Range("U" & activecell.row).value <> "OK" Then ActiveCell.EntireRow.Delete
    
    End Sub

    Or

    
    Sub Button8_Click() 'Delete
    
    If Range("U" & ActiveCell.Row).Value <> "ok" And Range("U" & ActiveCell.Row).Value <> "OK" Then ActiveCell.EntireRow.Delete
    
    End Sub
    Last edited by mehmetcik; 11-17-2016 at 02:24 PM.

  5. #5
    Registered User
    Join Date
    11-17-2016
    Location
    Chicago
    MS-Off Ver
    2007
    Posts
    7

    Re: Find string in specific column of active selected row...

    Thank you for the quick replies.
    I was looking for the solution like mehmetcik's. Simple and allows me to do per row manually.

    Works wonderfully! Thank you!

+ 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. Find last occurrence of a string in a specific column
    By Adam Brave in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2016, 11:39 AM
  2. [SOLVED] Can I use FIND function to find specific string in a single cell?
    By bonpara in forum Excel General
    Replies: 2
    Last Post: 10-05-2015, 05:46 PM
  3. Getting code to find the selected Active cell
    By JO505 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-19-2015, 03:12 PM
  4. [SOLVED] Find Specific Text in Text String and Return Value in Adjacent Column
    By watchouse in forum Excel General
    Replies: 2
    Last Post: 07-11-2012, 03:53 PM
  5. Find first non-zero value in specific cells within active row
    By touchofknowledge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2012, 02:44 PM
  6. Replies: 1
    Last Post: 01-15-2010, 05:29 AM
  7. How to obtain the number of Column and Row from selected (active)cell?
    By And1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2005, 05:30 PM

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