+ Reply to Thread
Results 1 to 3 of 3

What is the fastest most efficient way to find and replace things in cells?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2014
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    27

    What is the fastest most efficient way to find and replace things in cells?

    Hi, I am searching for a certain word in a sheet of thousands of cells and replacing it with another. I have tried to do both for each cell in the range and find and replace but they both take a while. Is there a more efficient faster way to do this? Thank You

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: What is the fastest most efficient way to find and replace things in cells?

    How many cells are we talking here?

    I just did a find and replace on 385,600 cells, making 158,711 replacements, and it took about 4 seconds.

    Another on 1,156,800 cells, finding 53,645 replacements, in 2 seconds.

    A third on 2,313,600 cells, finding 257,227 replacements, in 6 seconds....



    I think find and replace is about as fast as you are going to get. My times might be faster because of the hardware I am using, (8gb ram, 64 bit office, and a core i5)
    Last edited by Speshul; 10-27-2014 at 04:10 PM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Registered User
    Join Date
    04-04-2014
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: What is the fastest most efficient way to find and replace things in cells?

    Sub UpdateAirnRail()
    Application.ScreenUpdating = False
    
    Dim countriesup As String
    countriesup = ThisWorkbook.Sheets("Data").Range("B3").Value
    
    stopped = False
    UserForm.Show
    
    'copy and paste for Data
    
    Workbooks(namess).Sheets("Transaction Reporting").Activate
    With ActiveSheet
    
    Dim lr As Long
    Dim lc As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    
        Range(Cells(1, 1), Cells(lr, lc)).AutoFilter
    
        ActiveSheet.Range(Cells(1, 1), Cells(lr, lc)).AutoFilter Field:=1, Criteria1:=countriesup
        Range(Cells(2, 1), Cells(lr, 3)).SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Sheets("data").Range("B3").PasteSpecial xlPasteValues
        Range(Cells(2, 6), Cells(lr, lc)).SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Sheets("data").Range("E3").PasteSpecial xlPasteValues
    
    End With
    
    'delete adjustment for Data
    
    ThisWorkbook.Sheets("Data").Activate
    
    
    With ActiveSheet
    
    Dim lrs As Long
    lrs = Cells(Rows.Count, 2).End(xlUp).Row
    
    
    For Each Cell In Range("C3:C" & lrs)
        If Cell.Value = "Adjustment to get to Market P&L Transactions" Then
        Rows(Cell.Row).Delete
        End If
    Next Cell
    
    ActiveSheet.Calculate
    
    
    End With
    
    'copy and paste for status
    
    Workbooks(namess).Sheets("Status_Official").Activate
    With ActiveSheet
    
    Dim lr2 As Long
    Dim lc2 As Long
    lr2 = Cells(Rows.Count, 1).End(xlUp).Row
    lc2 = Cells(1, Columns.Count).End(xlToLeft).Column
    
        Range(Cells(1, 1), Cells(lr2, lc2)).AutoFilter
        ActiveSheet.Range(Cells(1, 1), Cells(lr2, lc2)).AutoFilter Field:=1, Criteria1:=countriesup
        Range(Cells(2, 1), Cells(lr2, 3)).SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Sheets("status").Range("B3").PasteSpecial xlPasteValues
        Range(Cells(2, 6), Cells(lr2, lc2)).SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Sheets("status").Range("E3").PasteSpecial xlPasteValues
    
    End With
    
    'Delete adjustment for status
    
    ThisWorkbook.Sheets("Status").Activate
    
    With ActiveSheet
    
    Dim lrss As Long
    lrss = Cells(Rows.Count, 2).End(xlUp).Row
    lcss = Cells(5, Columns.Count).End(xlToLeft).Column
    
    
    For Each Cell In Range("C3:C" & lrss)
        If Cell.Value = "Adjustment to get to Market P&L Transactions" Then
        Rows(Cell.Row).Delete
        End If
    Next Cell
    Range(Cells(3, 5), Cells(lrss, lcss)).Replace What:="Potential Loss", Replacement:="works", LookAt:=xlPart
    
    
    End With
    
    Application.ScreenUpdating = True

    This is my macro, it does more things updating a bunch of stuff. And it is about 300k cells.

+ 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] Fastest way to find a duplicate value in two large columns
    By ArnolddG in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-28-2014, 05:05 AM
  2. [SOLVED] Replace blank cells with ZERO using Find Replace
    By makinmomb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2014, 04:47 PM
  3. More efficient alternative to Find-Replace Loop?
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2010, 01:49 AM
  4. Find, and replace but copy cells before replace
    By raehippychick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2007, 08:16 AM
  5. [SOLVED] Fastest way to find item in an array.
    By WhytheQ in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2006, 06:20 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