简体   繁体   中英

Copy cells if value is higher than another cell

I have a cell ( U4 , for example) where I insert a value. I'll call it A, for example.

I want to copy all the values in Column K higher than A (starting in row 4), and place them in Column N (starting in row 4 also). Besides that, i want to copy the correspondent values in Column L and place them in column O.

Right now I have this, just for Column K:

A = Range("U4").Value
Cotacopy = 4
With Range("K4")
If .Cells(1, 1).Value > A Then
      Range(.Cells(1, 1), .End(xlDown)).Copy Destination:=Sheets("Cálculo").Range("N" & Cotacopy)
    x = x + 1
Else
End If
End With

I don't know if this is entirely correct, i'm adapting another process where i copy all the cells in one column that have value.

How about the following For loop :

Sub CopyHigherValue()

Dim lastrow As Long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

y = 4

For x = 4 To lastrow
    If Cells(x, 1).Value < Cells(x, 11).Value Then
          Cells(y, 14).Value = Cells(x, 11).Value
          Cells(y, 15).Value = Cells(x, 12).Value
          y = y + 1
    End If
Next x

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM