• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

copy data to other sheet based on conditions

I have this excel sheet which I'm attaching. In the first column I have some numbers and the 2nd column I have a yes/no value where yes is indicated by a value of '1'. I wish to copy the values from the 1st column when the row of the 2nd column equals '1'. How do I do this? I guess with some vb script?

Can someone give me some code in vb because I'd like to learn it too?

If there is an easier way as well can you please show it to me?

Thank you,
Victor copy-data-to-other-sheet.xls
0
Victor Kimura
Asked:
Victor Kimura
1 Solution
 
rlandquistCommented:
Where do you want to copy the values TO?
0
 
krishnakrkcCommented:
Hi,

Try this

Kris
Sub kTest()
Dim k(), ka, i As Long, n As Long
ka = [a1].CurrentRegion.Resize(, 2)
ReDim k(1 To UBound(ka, 1), 1 To UBound(ka, 2))
For i = 2 To UBound(ka, 1)
    If ka(i, 2) = 1 Then
        n = n + 1
        k(n, 1) = ka(i, 1): k(n, 2) = ka(i, 2)
    End If
Next
Sheets("Sheet2").Range("a1").Resize(n, 2).Value2 = k
End Sub

Open in new window

0
 
Victor KimuraAuthor Commented:
Thank you. Works nice.
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now