Hi all,
I have got a macro that should select any cells within column C with a date value greater than the value I have entered into A1 I have ran the program and it doesn't cause any faults however It isn't selecting anything I'm sure my mistake is obvious any help would be appreciated the code is below:
Sub SelectByCellValue()
Dim lastrow As Long
Dim xRg As Range, yRg As Range
With ThisWorkbook.Worksheets("Sheet2")
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
Application.ScreenUpdating = False
For Each xRg In .Range("C1:C" & lastrow)
'a1 contains a date value
If Range("a1").FormulaR1C1 = "=IF(RC[-3]<RC[-1],1,0)" Then
If yRg Is Nothing Then
Set yRg = .Range("A" & xRg.Row).Resize(, 2)
Else
Set yRg = Union(yRg, .Range("A" & xRg.Row).Resize(, 2))
End If
End If
Next xRg
Application.ScreenUpdating = True
End With
If Not yRg Is Nothing Then yRg.Select
End Sub
I have got a macro that should select any cells within column C with a date value greater than the value I have entered into A1 I have ran the program and it doesn't cause any faults however It isn't selecting anything I'm sure my mistake is obvious any help would be appreciated the code is below:
Sub SelectByCellValue()
Dim lastrow As Long
Dim xRg As Range, yRg As Range
With ThisWorkbook.Worksheets("Sheet2")
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
Application.ScreenUpdating = False
For Each xRg In .Range("C1:C" & lastrow)
'a1 contains a date value
If Range("a1").FormulaR1C1 = "=IF(RC[-3]<RC[-1],1,0)" Then
If yRg Is Nothing Then
Set yRg = .Range("A" & xRg.Row).Resize(, 2)
Else
Set yRg = Union(yRg, .Range("A" & xRg.Row).Resize(, 2))
End If
End If
Next xRg
Application.ScreenUpdating = True
End With
If Not yRg Is Nothing Then yRg.Select
End Sub