# IF statement is not working

#### aayaanmayank

##### Board Regular
Hi All,

Can anyone help me out on below code.

I have to update final rating in column D. following is the sequence if Column has rating then update in column d, else copy rating from column b & if column a & b does not have rating the copy rating from column c

 OP PO PO1 Final A A A A A A A A A A A A A A A A B A A A A A A A A A A A

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>

Code:
``````Sub mi()

Set FL = ThisWorkbook.Worksheets("Export Worksheet")

LASTROW = FL.Range("A" & Rows.Count).End(xlUp).Row

For U = 2 To LASTROW

If Cells(U, "c").Value = True Then
Cells(U, "C").Copy
Cells(U, "F").PasteSpecial

ElseIf Cells(U, "D").Value = True Then
Cells(U, "D").Copy
Cells(U, "F").PasteSpecial

End If
Next
End Sub``````

### Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},\$Z\$1:\$Z\$99,\$Y\$1:\$Y\$99),2,False) to lookup Y values to left of Z values.

#### sergioMabres

##### Well-known Member
Hi aayaanmayank ,
The line "If Cells(U, "c").Value = True Then" is wrong use <>"" like showed below
Code:
``````...
If Cells(U, "c").Value <> "" Then
Cells(U, "C").Copy
Cells(U, "F").PasteSpecial

ElseIf Cells(U, "D").Value <> "" Then
Cells(U, "D").Copy
Cells(U, "F").PasteSpecial

End If
...``````
Cheers
Sergio

Last edited:

#### Finalfight40

##### Active Member
Is something like this what you are looking for?

Code:
``````Sub mi()

Set FL = ThisWorkbook.Worksheets("[COLOR=#333333]Export Worksheet[/COLOR]")

LASTROW = Application.Max(FL.Range("A" & Rows.Count).End(xlUp).Row, FL.Range("B" & Rows.Count).End(xlUp).Row, FL.Range("C" & Rows.Count).End(xlUp).Row)

For U = 2 To LASTROW

If Not IsEmpty(Cells(U, 1)) Then
Cells(U, 4).Value = Cells(U, 1).Value
ElseIf Not IsEmpty(Cells(U, 2)) Then
Cells(U, 4).Value = Cells(U, 2).Value
ElseIf Not IsEmpty(Cells(U, 3)) Then
Cells(U, 4).Value = Cells(U, 3).Value
End If

Next
End Sub``````

Last edited:

#### vds1

##### Well-known Member
Excel formula in D2,

Code:
``=IF(A2="",IF(B2="",IF(C2="","Can't Determine",C2),B2),A2)``

• veejayc

#### Fluff

##### MrExcel MVP, Moderator
Code:
``````Sub aayaanmayank()
With Sheets("Export Worksheet")
With .Range("F2", .Range("A" & Rows.Count).End(xlUp).Offset(, 5))
End With
End With
End Sub``````