+ Reply to Thread
Results 1 to 8 of 8

Find text in cell using cells object with-in IF Then statement

Hybrid View

DevfromCorrie Find text in cell using cells... 05-03-2014, 09:59 AM
patel45 Re: Find text in cell using... 05-03-2014, 10:41 AM
stnkynts Re: Find text in cell using... 05-03-2014, 10:50 AM
DevfromCorrie Re: Find text in cell using... 05-05-2014, 01:46 PM
stnkynts Re: Find text in cell using... 05-05-2014, 03:43 PM
DevfromCorrie Re: Find text in cell using... 05-06-2014, 01:59 PM
stnkynts Re: Find text in cell using... 05-06-2014, 04:13 PM
DevfromCorrie Re: Find text in cell using... 05-07-2014, 02:50 AM
  1. #1
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Find text in cell using cells object with-in IF Then statement

    Try this:

    Sub Summary()
    Dim ws As Worksheet:    Set ws = Sheets("Statement of Profit & Loss")
    Dim LR As Long
    Dim rCell As Range
    
    LR = ws.Range("E" & Rows.Count).End(xlUp).Row
    
    For Each rCell In ws.Range("E1:E" & LR)
        If Not InStr(1, rCell.Value, "[Tx]") = 0 Then
            With rCell.EntireRow.Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .Weight = xlThin
            End With
            With rCell.EntireRow.Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .Weight = xlMedium
            End With
        ElseIf Not InStr(1, rCell.Value, "[H]") = 0 Then
            rCell.Offset(, -1).Clear
            rCell.Offset(, -4).Clear
            rCell.Offset(, 1).Clear
            rCell.Offset(, 4).Clear
        ElseIf IsEmpty(rCell) Then
            rCell.EntireRow.Clear
        End If
    Next rCell
    
    End Sub

  2. #2
    Registered User
    Join Date
    05-16-2012
    Location
    Guernsey, C.I
    MS-Off Ver
    Microsoft 365 MSO (Version 2402 Build 16.0.17328.20550) 64-bit
    Posts
    39

    Re: Find text in cell using cells object with-in IF Then statement

    Quote Originally Posted by stnkynts View Post
    Try this:

    Sub Summary()
    Dim ws As Worksheet:    Set ws = Sheets("Statement of Profit & Loss")
    Dim LR As Long
    Dim rCell As Range
    
    LR = ws.Range("E" & Rows.Count).End(xlUp).Row
    
    For Each rCell In ws.Range("E1:E" & LR)
        If Not InStr(1, rCell.Value, "[Tx]") = 0 Then
            With rCell.EntireRow.Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .Weight = xlThin
            End With
            With rCell.EntireRow.Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .Weight = xlMedium
            End With
        ElseIf Not InStr(1, rCell.Value, "[H]") = 0 Then
            rCell.Offset(, -1).Clear
            rCell.Offset(, -4).Clear
            rCell.Offset(, 1).Clear
            rCell.Offset(, 4).Clear
        ElseIf IsEmpty(rCell) Then
            rCell.EntireRow.Clear
        End If
    Next rCell
    
    End Sub

    Hi stnkynts,
    Thanks for the code this works, could the last column used be include to replace EntireRow for the cell borders formatting, apologies I should have included this is my initial request?

+ 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 some cell's text in another column and get the text of those cells
    By simone77 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-25-2013, 11:39 AM
  2. find and list cells based on text on its next cell
    By calif in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-13-2013, 04:24 AM
  3. Formula to Find If Text In a Cell Matches Another Range of Cells
    By purplesamcat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-03-2013, 07:45 PM
  4. Problems with Cells.Find. Object/Block variable not set
    By mattisch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2007, 09:06 AM
  5. find text in a cell and make cell 2 cells below that active
    By shark102 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2005, 10:05 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