+ Reply to Thread
Results 1 to 18 of 18

Select each row one by one and check for a substring in each cell of it

Hybrid View

Abhushan86 Select each row one by one... 04-27-2012, 12:36 AM
jraj1106 Re: Select each row one by... 04-27-2012, 12:42 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 12:55 AM
jraj1106 Re: Select each row one by... 04-27-2012, 01:00 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 01:04 AM
jraj1106 Re: Select each row one by... 04-27-2012, 01:16 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 01:33 AM
jraj1106 Re: Select each row one by... 04-27-2012, 01:47 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 02:00 AM
Trebor76 Re: Select each row one by... 04-27-2012, 01:27 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 01:34 AM
Rick Rothstein Re: Select each row one by... 04-27-2012, 01:37 AM
jraj1106 Re: Select each row one by... 04-27-2012, 02:20 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 02:32 AM
jraj1106 Re: Select each row one by... 04-27-2012, 02:38 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 03:01 AM
Abhushan86 Re: Select each row one by... 04-27-2012, 03:38 AM
jraj1106 Re: Select each row one by... 04-27-2012, 06:02 AM
  1. #1
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Select each row one by one and check for a substring in each cell of it

    Try this code:

    Sub CopyPaste2()
    Dim WS As Worksheet
    Dim rcnt As Long

    rcnt = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Sheet1").Range("A1:E" & rcnt).Select
    Selection.Copy

    Set WS = Sheets.Add
    ActiveSheet.Name = "Test" 'renames the sheet2 to test
    ActiveSheet.Paste 'pastes the copied data

    Call substringdelete
    End Sub

    Sub substringdelete()
    Dim rcnt As Long, col As Integer

    rcnt = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    col = 3

    For i = 2 To rcnt
    While ActiveSheet.Cells(i, col).Value <> ""
    If InStr(1, ActiveSheet.Cells(i, col).Value, "good morning") > 0 Then
    ActiveSheet.Rows(i & ":" & i).Delete
    End If
    col = col + 1
    Wend
    col = 3
    Next
    End Sub
    Click *, if my suggestion helps you. Have a good day!!

  2. #2
    Registered User
    Join Date
    04-27-2012
    Location
    New Delhi
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Select each row one by one and check for a substring in each cell of it

    Quote Originally Posted by jraj1106 View Post
    Try this code:
    Hi, when I run this code It shows me a type mismatch, is it because of the space condition that we are checking for?

    Also another thing, how do I check for multiple conditions in this itself, I mean to say that If in addition to "good morning" I want other phrases as well, say for example "good day" or "good night" then also I need to delete that row.
    Last edited by Abhushan86; 04-27-2012 at 02:34 AM. Reason: Adding relevant information and details

+ 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.6.0 RC 1