IF statement is not working

aayaanmayank

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

Some videos you may like

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
Joined
Feb 24, 2013
Messages
946
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
Joined
Apr 24, 2018
Messages
273
Office Version
365
Platform
Windows
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
Joined
Oct 5, 2011
Messages
1,189
Excel formula in D2,

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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,626
Office Version
365
Platform
Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,099,029
Messages
5,466,116
Members
406,467
Latest member
bpat83

This Week's Hot Topics

Top