Link to home
Start Free TrialLog in
Avatar of LarsDyrby
LarsDyrby

asked on

Copy value to another sheet when condition is met

Can somebody help me with some VBA-code that loops through a range and copies the value in a cell to another sheet when condition is met.

Example:

Check if the value of cells A1:A10 = x, if yes copy the corresponding values from B1:B10 to another sheet

Best wishes
Lars
Avatar of Rgonzo1971
Rgonzo1971

Hi,

Could you be more specific?

Sub macro()
For Each c In Range("A1:A10")
    If LCase(c) = "x" Then
        c.Offset(0, 1).Copy Destination:=Worksheets("Sheet3").Range("B" & Cells.Rows.Count).End(xlUp).Offset(1)
        c.EntireRow.Delete
    End If
Next
End Sub

Open in new window

Regards
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LarsDyrby

ASKER

Used the advanced filter

Thx to Rob