I have a set of rows and columns range is A:AC and Rows count may be anything
Fixing the sheet and range and calculating RowCount and ColumnCount using this
Dim sheet As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Set sheet = ActiveWorkbook.Worksheets(1)
LastRow = sheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn = sheet.Range("A1").CurrentRegion.Columns.Count
Set selectedRange = Range("A1:AC" & LastRow)
- First Condition:
I am trying to compare column F to AC should have either 0 or 1. and found that by using
For i =1 To LastRow
For j = 6 To LastColumn
If Cells(i, j).Value <> 0 And Cells(i, j) <> 1 Then
Cells(i, j).Interior.Color = vbGreen
End If
If Cells(i, j).Value > 1 Then
Cells(i, j).Interior.Color = vbRed
End If
Next j
Next i
- Second Condition
Out of these columns I should have only one column should have 1 and remaining as 0
I tried this and it is throwing different error codes for each run
- Third Condition
Find duplicate rows from A:AC
I need to highlight entire row which has the error
But I have done which Column has error
with this statement
Cells(i, j).Interior.Color = vbRed