Solved

copy rows that contain a specific word

Posted on 2010-11-26
5
245 Views
Last Modified: 2012-05-10
hi
I wonder if anyone can help with the following macro. In column B and are the persons firstname, columnc the last name, In column D is the attendance column, with a list box with the options YES/NO. What I want to do is when someone presses a button, and if yes appears next to the person first/lastname it copies these names to another sheet (sheet2) to B28 (firstname) and C28 (lastname) and B29/C29 and so on....is this possible?
0
Comment
Question by:kwatt562
[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
5 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 34220229
Do you have a sample file?

Cheers

Dave
0
 

Author Comment

by:kwatt562
ID: 34220250
0
 

Author Comment

by:kwatt562
ID: 34220253
Hi Dave, file, attached.
Thanks a lot
0
 
LVL 3

Accepted Solution

by:
byronwall earned 500 total points
ID: 34220805
Please see the attached spreadsheet for the full details.  The following code is executed at the button press:
Sub CopyYesNames()
    Dim start As Range
    Dim names_found As Integer
    
    Set start = Sheets("Sheet1").Range("D14")
    
    names_found = 0
    
    For Each cell In Range(start, start.End(xlDown))
        If cell = "YES" Then
            
            Sheets("Sheet2").Range("B28").Offset(names_found, 0) = cell.Offset(, -2)
            Sheets("Sheet2").Range("C28").Offset(names_found, 0) = cell.Offset(, -1)
        
            names_found = names_found + 1
        End If
    Next cell
End Sub

Open in new window


This assumes that the sheet names and cell positions will not change.  The code will adapt to as many names as desired.  It requires that the yes/no column not have any blanks between entries.  A yes answer must be indicated by YES (case sensitive).

Also, you mention splitting the first and last name, but the output sheet indicates name and ID number.  I have made the code follow the output sheet.  You could split the name into first and last and copy that instead.

Please follow up if this is not what you wanted.
 Book1.xlsm
0
 

Author Closing Comment

by:kwatt562
ID: 34222620
Genius! works perfectly
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

733 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