Solved

Copy value to another sheet when condition is met

Posted on 2014-03-24
3
856 Views
Last Modified: 2014-03-31
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
0
Comment
Question by:LarsDyrby
3 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39950364
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
0
 
LVL 32

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39950958
You can do this without VBA using the Advanced Filter feature.

To make a copy to another location, select that location before instigating the feature.

The destination sheet has to have the same column headers (or a selection of) as the source data.

Thanks
Rob H
0
 

Author Closing Comment

by:LarsDyrby
ID: 39967183
Used the advanced filter

Thx to Rob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now