PDA

View Full Version : Apply macros on filtered columns



teodormircea
03-10-2009, 07:07 AM
Hello Forum

I've made a macros to compare 2 columns and put comments in 3rd one.Is working good but my code is comparing the hidden values from the column if a have filtered applied, i sow that when i rested the filter.
What i have to change to make it work only on visible cells.
Here attached my file.

Kenneth Hobs
03-10-2009, 09:36 AM
Maybe:
For i = 2 To LastRow
If Cells(i, Z).EntireRow.Hidden = False Then _
Cells(i, Z).Value = IIf(Cells(i, x).Value = Cells(i, Y).Value, "OK", "NOK")
Next i

Bob Phillips
03-10-2009, 09:38 AM
Sub comparer()
Dim x As Long
Dim Y As Long
Dim Z As Long
Dim r As Range
Dim s As Range
Dim t As Range
Dim i As Long
Dim LastRow As Long

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

x = CLng(InputBox(Prompt:="Column1?"))
If (x < 1) + (x > Columns.Count) Then Exit Sub
LastRow = ActiveSheet.Cells(Rows.Count, x).End(xlUp).Row
Y = CLng(InputBox(Prompt:="Column2?"))
If (Y < 1) + (Y > Columns.Count) Then Exit Sub
LastRow = ActiveSheet.Cells(Rows.Count, Y).End(xlUp).Row
Z = CLng(InputBox(Prompt:="Result?"))
If (Y < 1) + (Y > Columns.Count) Then Exit Sub

LastRow = Cells(Rows.Count, x).End(xlUp).Row
Cells(2, Z).Resize(LastRow - 1).ClearContents
For i = 2 To LastRow
If Not Rows(i).Hidden Then
Cells(i, Z).Value = IIf(Cells(i, x).Value = Cells(i, Y).Value, "OK", "NOK")
'ActiveCell(i, Z).FormulaR1C1 = "=IF(RC[-2]=RC[-1],""OK"",""KO"")"
End If
Next i

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub