Results 1 to 9 of 9

Need help writing a better loop

Threaded View

alexduy Need help writing a better... 01-28-2021, 04:04 PM
alansidman Re: Need help writing a... 01-28-2021, 04:29 PM
maniacb Re: Need help writing a... 01-28-2021, 04:58 PM
alexduy Re: Need help writing a... 01-28-2021, 07:26 PM
alansidman Re: Need help writing a... 01-28-2021, 05:12 PM
alexduy Re: Need help writing a... 01-28-2021, 07:25 PM
maniacb Re: Need help writing a... 01-28-2021, 08:25 PM
AlphaFrog Re: Need help writing a... 01-28-2021, 08:41 PM
alexduy Re: Need help writing a... 01-29-2021, 12:33 AM
  1. #1
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Need help writing a better loop

    I need to find a better way to write the code below. The code below works great, but then it's looping through my whole data in order to accomplish what I want. The thing is my data can have 40,000 rows and it's taking forever. Is there a better way to write this?

    Basically, what the code below doing is looping through my data and evaluate the data in column D and G. If they are both "CONTRACT" and "ABC COMPANY". If that's the case, it will change the value in column D, which is "CONTRACT" to "CONTRACT ENG".


    I think another way to write the code is to do an autofilter and filer column D and G by "CONTRACT" and "ABC COMPANY". Once it's filtered, it would only be less than 20 rows of data that match that criteria. I can loop through those 20 rows, it's much faster than have the macros loop through 40k rows. I just don't know how to do it. Can someone help me?

    Last_Row = Cells(Rows.Count, "D").End(xlUp).Row
    
    Range("D2").Activate
    
    For I = 2 To Last_Row
    
    If ActiveCell.Value = "CONTRACT" And ActiveCell.Offset(0, 3) <> "ABC COMPANY" Then
    
    ActiveCell.Value = "CONTRACT ENG"
    
    
    ActiveCell.Offset(1, 0).Activate
    
    Else
    
    ActiveCell.Offset(1, 0).Activate
    
    End If
    
    Next I
    Attached Files Attached Files
    Last edited by alexduy; 01-28-2021 at 07:31 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 08-11-2016, 09:28 PM
  2. Writing a loop to look up data
    By JesseV92 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2016, 08:22 AM
  3. Writing to cell stops for loop
    By Amathanio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-04-2016, 06:40 AM
  4. Problem writing a loop
    By themindseye in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2014, 09:30 AM
  5. Need help writing Loop syntax
    By sslack88 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-26-2012, 11:02 PM
  6. Issue writing a loop
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2008, 08:27 AM
  7. help writing loop
    By robhargreaves in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2005, 06:05 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