+ Reply to Thread
Results 1 to 8 of 8

Find and Replace code help

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Find and Replace code help

    Hello,
    I am writing to seek help in implementing the following vba macro logic below:

    If column E equals to “Auto”, “RMBS”, “CMBS”, “CLO”, “Student” or “Consumer” then do nothing,
    Else
    If there is any other value besides the one above THEN change it to “Esoteric”.

    I am currently using the following find and replace code below but there are many variations in the large dataset and which is making it hard to manually input in the values into the code.

    Sub find_replace()
    
    Range("E1").Select
        Cells.Replace What:="Future flow ABS", Replacement:="Esoteric ABS", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            
        Cells.Replace What:="Infrastructure ABS", Replacement:="Esoteric ABS", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    End Sub
    I have also attached workbook example with the dataset, indicating the yellow highlighted names, need to be changed into “Esoteric”.
    example_set.xls

    Please Note: the words such as Auto and many more mentioned above are not always in the same position in the cells
    .

    Any help with this issue, would be a great help.
    Thanks in advance for your help and time.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and Replace code help

    Maybe:

    Sub missy22()
    
    Dim rcell As Range
    Dim lr As Long
    
    Application.ScreenUpdating = False
    
    lr = Cells(Rows.Count, 5).End(xlUp).Row
    
    For Each rcell In Range("E1:E" & lr)
    
        If rcell <> "Auto" And rcell <> "RMBS" And rcell <> "CMBS" And rcell <> "CLO" And rcell <> "Student" And rcell <> "Consumer" Then
        
            rcell.ClearContents
            rcell.Replace "", "Esoteric", xlWhole
            
        End If
        
    Next rcell
    
    Application.ScreenUpdating = True
       
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Find and Replace code help

    Dear John,

    Thank you for your response and suggestions. I am really sorry but the code also converts row 3 and rows 8-11. The code should only convert rows from 12 to 15 into "Esoteric" and leave the rest the cells in column E.

    thank you for your help.

  4. #4
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Find and Replace code help

    Hi.

    Sub FINDREPLACE()
        Dim rcnt As Long, colEstr As Variant
        
        rcnt = Range("E" & Rows.Count).End(xlUp).Row
        
        For i = 1 To rcnt
            colEstr = Trim(Range("E" & i).Text)
            MsgBox InStr(1, colEstr, "RMBS")
            If InStr(1, colEstr, "Auto") = 0 And InStr(1, colEstr, "RMBS") = 0 And InStr(1, colEstr, "CMBS") = 0 And InStr(1, colEstr, "CLO") = 0 And InStr(1, colEstr, "Student") = 0 And InStr(1, colEstr, "Consumer") = 0 Then
                Range("E" & i) = "Esoteric"
            End If
        Next
    End Sub
    Click *, if my suggestion helps you. Have a good day!!

  5. #5
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Find and Replace code help

    Quote Originally Posted by jraj1106 View Post
    Hi.

    Sub FINDREPLACE()
        Dim rcnt As Long, colEstr As Variant
        
        rcnt = Range("E" & Rows.Count).End(xlUp).Row
        
        For i = 1 To rcnt
            colEstr = Trim(Range("E" & i).Text)
            MsgBox InStr(1, colEstr, "RMBS")
            If InStr(1, colEstr, "Auto") = 0 And InStr(1, colEstr, "RMBS") = 0 And InStr(1, colEstr, "CMBS") = 0 And InStr(1, colEstr, "CLO") = 0 And InStr(1, colEstr, "Student") = 0 And InStr(1, colEstr, "Consumer") = 0 Then
                Range("E" & i) = "Esoteric"
            End If
        Next
    End Sub
    Thank you so much for your code solution. The code works great. Thank you for your time and help.
    I very grateful to your help.
    Thanks a million.

  6. #6
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Find and Replace code help

    What about "Synthetic SF CDO" and "CDO"?

  7. #7
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Find and Replace code help

    Dear jraj1106,

    The code works great, I am really sorry for not mentioning in the problem but column E has few blanks and the code translate the blanks into "Esoteric". Is it possible to ignore the blanks cells in column E.

    I really appreciate your time and help.
    Last edited by missy22; 01-24-2013 at 08:37 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Find and Replace code help

    Okay..

    Happy to help you. Please click the star below.

    Have a great day too..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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