Solved

copy rows that contain a specific word

Posted on 2010-11-26
5
241 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

21 Experts available now in Live!

Get 1:1 Help Now