Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 424
- Office Version
- 365
- Platform
- Windows
- Mobile
I change a value in column J or 10 and the code starts to run then it crashes the workbook!
Any idea why?
Any idea why?
VBA Code:
Sub BOReason()
Dim Ws As Worksheet
Dim LRow As Long
Dim x As Variant, y As Variant, i As Variant, MatchData As Variant
Dim rng As Range, Sourcerng As Range, Comparerng As Range, Fill As Range
On Error Resume Next
Set Ws = ActiveSheet
LRow = Ws.Range("A1").End(xlDown).Row
Set rng = Ws.Range("A1:A" & LRow)
With rng
.AutoFilter 1, Format(Date, "dd/mm/yyyy"), 2, Format(Date - 1, "dd/mm/yyyy")
End With
Set Comparerng = Ws.Range("E2:E" & LRow)
Set Sourcerng = Ws.Range("J2:J" & LRow)
Set Fill = Ws.Range("J2:J" & LRow + 1)
For Each x In Comparerng.SpecialCells(xlCellTypeVisible)
For Each y In Comparerng.SpecialCells(xlCellTypeVisible)
For Each i In Sourcerng.SpecialCells(xlCellTypeVisible)
On Error Resume Next
If x = y Then
Fill = i
End If
Next i
Next y
Next x
Ws.AutoFilter.ShowAllData
End Sub