Sorting and Summarizing data

B

bundyloco

Hello,

I have a workbook with no more tha five worksheets. The first worksheet
is going to be a summary. The remaining four sheets are each day of the
workweek.

I want to write a macro that will look at a column of data from one of
the workweek worksheets and copy it the summary worksheet. The only
catch is that I only want to copy it if the first character is the
letter Y. Can anyone give me some help or point me in the right
direction, such as an array or some tips like that.

Thanks in advance.
 
G

Guest

Try this:

Sub SelectY()

Set ws1 = Worksheets("Sheet1") ' One of your workweek sheets
Set ws2 = Worksheets("Sheet2") ' Your Summary sheet

' Assume data is in column A
Set rng = ws1.Range("a1:a" & Cells(Rows.Count, "a").End(xlUp).Row)

' Set range to collate "Y" cells
Set Yrng = Nothing

For Each c In rng ' Loop through your input data

If Left(c, 1) = "Y" Then ' Starts with "Y" ....
If Yrng Is Nothing Then
Set Yrng = c
Else
Set Yrng = Union(Yrng, c)
End If
End If

Next c
' Set output column e.g. D1 in your Summary sheet
Set orng = ws2.Range("d1")
Yrng.Copy orng

End Sub


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top