PDA

View Full Version : Loop and Check For Values In Entire Column in Excel



Jeff5019
05-01-2012, 09:29 PM
I need this to check every cell in these columns. Not just the cells in row 2. Any assistance would be greatly appreciated.



If Sheets("RSL").Range("M2") = Sheets("FailedSpots").Range("L2") Then

If Sheets("RSL").Range("K2") > Sheets("FailedSpots").Range("M2") Then

Sheets("RSL").Range("K2").Value = Sheets("FailedSpots").Range("M2").Value

End If

End If

Admin
05-01-2012, 10:16 PM
Hi Jeff5019

Welcome to ExcelFox !!

add code tags while posting codes :)

Admin
05-01-2012, 10:21 PM
Hi

try


Sub kTest()

Dim LastRow As Long, i As Long
Dim RSL_Data, FS_Data, r As Range

With Sheets("RSL")
LastRow = .Range("m" & .Rows.Count).End(xlUp).Row
Set r = .Range("k2:m" & LastRow)
RSL_Data = r.Value2
End With

With Sheets("FailedSpots")
LastRow = .Range("m" & .Rows.Count).End(xlUp).Row
FS_Data = .Range("l2:m" & LastRow)
End With


For i = 1 To LastRow - 1
If RSL_Data(i, 3) = FS_Data(i, 1) Then
If RSL_Data(i, 1) > FS_Data(i, 2) Then
RSL_Data(i, 1) = FS_Data(i, 2)
End If
End If
Next

r = RSL_Data

End Sub

Excel Fox
05-01-2012, 10:34 PM
Added a more generic thread title. Jeff, for posterity and for the sake of people searching for similar queries in Excel, it would be best to provide a thread title that describes the objective in a more concise manner.