?
Solved

copy rows that contain a specific word

Posted on 2010-11-26
5
Medium Priority
?
249 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

777 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