Anaya Zeeshan
New Member
- Joined
- Nov 4, 2021
- Messages
- 33
- Office Version
- 365
- Platform
- Windows
I am trying to write a code to loop through a range and copy cell values if the cell is not blank and cell value doesn't already exists in the range.
I have written this code but its checking the cell above but I want to check check MyValue in entire range not just the cell above. if myValue is unique only then I want the value too be pasted in column T
Sub Testing()
Dim i As Long
Dim LastRow As Long
Dim MyValue As Variant
Const StartRow As Byte = 4
LastRow = Range("P" & Rows.Count).End(xlUp).Row
For i = StartRow To LastRow
MyValue = Range("P" & i).Value
If MyValue <> "" Then
If Range("p" & i + 1) <> MyValue Then
Range("T" & i).Value = MyValue
End If
End If
Next i
End Sub
I have written this code but its checking the cell above but I want to check check MyValue in entire range not just the cell above. if myValue is unique only then I want the value too be pasted in column T
Sub Testing()
Dim i As Long
Dim LastRow As Long
Dim MyValue As Variant
Const StartRow As Byte = 4
LastRow = Range("P" & Rows.Count).End(xlUp).Row
For i = StartRow To LastRow
MyValue = Range("P" & i).Value
If MyValue <> "" Then
If Range("p" & i + 1) <> MyValue Then
Range("T" & i).Value = MyValue
End If
End If
Next i
End Sub