Solved

Copy value to another sheet when condition is met

Posted on 2014-03-24
3
900 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

729 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