I didn't like my last macro I sent you. The code was too hard to follow. I
went looking for a more eligant method. Came up with a table driven version
of the macro. Let me know which you think is better.
Sub checkaddress()
Dim CellValue(8) As Variant
Dim MovedCell(8) As Variant
'Table of data in cells
'F = Full, E = empty, X= Don't Care
CellValue(0) = Array("F", "F", "E", "F", "X")
CellValue(1) = Array("F", "F", "E", "E", "F")
CellValue(2) = Array("F", "E", "F", "X", "X")
CellValue(3) = Array("F", "E", "E", "F", "X")
CellValue(4) = Array("F", "E", "E", "E", "F")
CellValue(5) = Array("E", "F", "F", "X", "X")
CellValue(6) = Array("E", "F", "E", "F", "X")
CellValue(7) = Array("E", "F", "E", "E", "F")
'Array of showing column data is move to
'X = Don't move
'A - E letter of column where data was move from
'Array represents columns A to E where data is move to
'First array member is column A, last is E
MovedCell(0) = Array("X", "X", "D", "X", "X")
MovedCell(1) = Array("X", "X", "E", "X", "X")
MovedCell(2) = Array("X", "C", "X", "X", "X")
MovedCell(3) = Array("X", "D", "X", "X", "X")
MovedCell(4) = Array("X", "E", "X", "X", "X")
MovedCell(5) = Array("B", "C", "X", "X", "X")
MovedCell(6) = Array("B", "D", "X", "X", "X")
MovedCell(7) = Array("B", "E", "X", "X", "X")
LastRowA = Cells(Rows.Count, "A").End(xlUp).Row
LastRowB = Cells(Rows.Count, "B").End(xlUp).Row
LastRowC = Cells(Rows.Count, "C").End(xlUp).Row
LastRowD = Cells(Rows.Count, "D").End(xlUp).Row
LastRowE = Cells(Rows.Count, "E").End(xlUp).Row
LastRow = LastRowA
If LastRowB > LastRow Then
LastRow = LastRowB
End If
If LastRowC > LastRow Then
LastRow = LastRowC
End If
If LastRowD > LastRow Then
LastRow = LastRowD
End If
If LastRowE > LastRow Then
LastRow = LastRowE
End If
For RowCount = 1 To LastRow
For TableCount = 0 To (UBound(CellValue, 1) - 1)
found = True
For ColOff = 0 To 4
If CellValue(TableCount)(ColOff) <> _
"X" Then
If CellValue(TableCount)(ColOff) = _
"F" Then
'table says cell if full but it is empty
If IsEmpty(Cells(RowCount, "A"). _
Offset(0, ColOff)) Then
found = False
Exit For
End If
Else
'table says cell if empty but it is full
If Not IsEmpty(Cells(RowCount, "A"). _
Offset(0, ColOff)) Then
found = False
Exit For
End If
End If
End If
Next ColOff
If found = True Then
For ColOff = 0 To 4
If MovedCell(TableCount)(ColOff) _
<> "X" Then
Cells(RowCount, "A"). _
Offset(0, ColOff) = _
Cells(RowCount, _
MovedCell(TableCount)(ColOff))
Cells(RowCount, _
MovedCell(TableCount)(ColOff)). _
ClearContents
End If
Next ColOff
End If
Next TableCount
Next RowCount
End Sub