Solved

Copy value to another sheet when condition is met

Posted on 2014-03-24
3
873 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 50

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 33

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

860 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