nawilliams
New Member
- Joined
- Jun 26, 2019
- Messages
- 3
The bellow macro was created to pull the notes from cells meeting specific criteria. That in mind, the code works perfectly and does exactly what is needed. the issue at hand is that the range the loop is running through can be anywhere from 1 to 10000. the loop can handle search for and pull the notes for around 50 rows but after that it stats to give the application not responding error after processing for sometime. if there is another method that this can be done please help!!
Code:
Sub Pull_Lead_Notes()
Dim CurRow As Integer
Dim Found As Variant
Dim LastFound As Variant
Dim ACell As Range
Dim DCell As Range
Dim JCell As Range
Dim NCell As Range
Dim LastRow As Long
Dim LastRow2 As Long
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WS1 = Worksheets("Table")
Set WS2 = Worksheets("Agent Access DB")
LastRow = WS1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
CurRow = 17
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For CurRow = 17 To LastRow
Set ACell = WS1.Range("A" & CurRow)
Set DCell = WS1.Range("D" & CurRow)
Set JCell = WS1.Range("J" & CurRow)
Set NCell = WS1.Range("N" & CurRow)
On Error Resume Next
Found = WS2.Columns("D").EntireRow.Find(What:=(DCell.Value), SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
LastFound = WS2.Columns("D").EntireRow.Find(What:=(DCell.Value), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If Err.Number = 91 Then
WS1.Range("O" & CurRow).Style = "Bad"
Else
WS1.Range("O" & CurRow).Style = "Good"
If WS2.Range("N" & Found).Value = "" Then
Else
For Found = Found To LastFound
If WS2.Range("A" & Found).Value = ACell.Value Then
If WS2.Range("J" & Found).Value = JCell.Value Then
NCell.Value = WS2.Range("N" & Found).Value
Exit For
Else
Found = WS2.Columns("D").EntireRow.Find(What:=(DCell.Text), SearchOrder:=xlByRows, SearchDirection:=xlNext, After:=Range("D" & Found)).Row - 1
End If
End If
Next Found
End If
End If
Next CurRow
LastRow = WS1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
WS1.Range("A17:N" & LastRow).Style = "Normal"
With ActiveSheet
.ListObjects.Add(xlSrcRange, Range("A16:N" & LastRow), , xlYes).Name = "TTable"
.Range("TTable[#All]").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), Header:=xlYes
.ListObjects("TTable").TableStyle = "TableStyleDark9"
.ListObjects("TTable").Unlist
End With
LastRow2 = WS1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Range("O" & LastRow2 & ":O" & LastRow + 1).Delete
Range("A1").Select
End Sub