Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hello all,
I have a For Each statement piece of code that adds a value to a column at the end of my report. My current code is processing 30k rows in excel and runs in 40 seconds. I was hoping someone may see a better way to write the code I have in a more efficient way to speed up the run time.
Any ideas are appreciated.
Here is the code:
I have a For Each statement piece of code that adds a value to a column at the end of my report. My current code is processing 30k rows in excel and runs in 40 seconds. I was hoping someone may see a better way to write the code I have in a more efficient way to speed up the run time.
Any ideas are appreciated.
Here is the code:
Code:
'----------------------------------------------------------------------------------------
'--- Using the Group List by Titles tag each record with Unique Name
'----------------------------------------------------------------------------------------
Sub GroupTitles()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim Count As String, OriginalTitle As String, GroupTitle As String
Dim ceLL As Range, ceLL2 As Range
Dim LastR1 As Long, LastR2 As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Set ws1 = Sheets("Download")
Set ws2 = Sheets("Lookup")
LastR1 = ws1.Range("G" & Rows.Count).End(xlUp).Row
LastR2 = ws2.Range("B" & Rows.Count).End(xlUp).Row
'ws1.Range("O2:O" & LastR1).ClearContents 'Clears the Group column First
For Each ceLL In ws2.Range("B2:B" & LastR2) 'Loops thru the list of Grouped Titles
If ceLL.Value <> "" Then
OriginalTitle = ceLL.Value
GroupTitle = ceLL.Offset(0, 1).Value
End If
For Each ceLL2 In ws1.Range("B2:B" & LastR1) 'Loops down the download sheet Column B
If ceLL2.Value = OriginalTitle Then
ceLL2.Offset(0, 13).Value = GroupTitle
Else: ceLL2.Offset(0, 13).Value = ceLL2.Value 'Brings in regular titles into the Grouped Column
End If
Next ceLL2
Next ceLL
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
End Sub
Last edited: