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

OPPOPO1Final
AAAA
AAA
AAA
AAA
AA
AB A
AAAA
AAA
AAA

<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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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