IF statement is not working

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
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

[TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]OP[/TD]
[TD="class: xl65, width: 64"]PO[/TD]
[TD="class: xl65, width: 64"]PO1[/TD]
[TD="class: xl65, width: 64"]Final[/TD]
[/TR]
[TR]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]B[/TD]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
[TR]
[TD="class: xl66"] [/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[TD="class: xl66"]A[/TD]
[/TR]
</tbody>[/TABLE]

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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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:
Upvote 0
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:
Upvote 0
Excel formula in D2,

Code:
=IF(A2="",IF(B2="",IF(C2="","Can't Determine",C2),B2),A2)
 
Upvote 0
Another option, based on your code rather than your description
Code:
Sub aayaanmayank()
   With Sheets("Export Worksheet")
      With .Range("F2", .Range("A" & Rows.Count).End(xlUp).Offset(, 5))
         .Value = Evaluate(Replace(Replace(Replace("if(@c<>"""",@c,if(@d<>"""",@d,@e))", "@c", .Offset(, -3).Address), "@d", .Offset(, -2).Address), "@e", .Offset(, -1).Address))
      End With
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top