Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 424
- Office Version
- 365
- Platform
- Windows
- Mobile
Please could someone help with this for some reason( Value Change macro) loop does not work. Say`s For with out next??
VBA Code:
Sub Value_Change()
Dim Ws As Worksheet
Dim LRow As Long
Dim rng As Range
Dim R As Integer
Set Ws = ActiveSheet
LRow = Ws.Range("J2").End(xlDown).Row
Set rng = Ws.Range("J2:J" & LRow)
For R = 2 To LRow
For Each Cell In rng
If rng.Cells(R, 10).Value <> rng.Cells(R - 1, 10).Value Then
Call BOReason
End If
R = R + R
Next Cell
End Sub
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