I
i_eat_pies
I have two sets of data where dataset 2 is a subset of dataset 1. I
would like to copy all rows in dataset1 where the same identifier is in
dataset2 to a new worksheet.
Dataset 1 has 12500 entries and dataset 2 has approx 2500 entries.
If the copy procedure is very intensive would deleting the rows in
dataset1 where the identifier cannot be found in dataset2 be quicker?
I have had a go this morning but it takes too long to process. What
could i change to improve performance - alternatively is there simply a
better way.
Any suggestions would be gratefully received as this is my first go at
VB.
Thanks.
----------------------------------------------
Sub Main()
Dim cnt As Integer, target As String
cnt = 0
Do While Worksheets(2).Cells(cnt + 1, 1) <> ""
target = Worksheets(2).Cells(cnt + 1, 1)
Call MarkGoodRows(target)
cnt = cnt + 1
Loop
Call ClearUp
End Sub
Sub MarkGoodRows(target)
Dim cnt As Integer
cnt1 = 1
Do While Worksheets(1).Cells(cnt1, 1) <> ""
If Worksheets(1).Cells(cnt1, 1) = target Then
Sheets(1).Cells(cnt1, 8) = "Good Point"
Exit Sub
End If
cnt1 = cnt1 + 1
Loop
End Sub
Sub ClearUp()
Dim cnt As Integer
cnt = 1
Do While Sheets(1).Columns(1).Row(cnt) <> ""
If Sheets(1).Columns(8).Row(cnt) = "Good Point" Then
Sheets(1).Columns(1).Row(cnt).Copy_destination
(Sheets(1).Columns(1).Row(cnt))
Sheets(1).Columns(2).Row(cnt).Copy_destination
(Sheets(1).Columns(2).Row(cnt))
Sheets(1).Columns(3).Row(cnt).Copy_destination
(Sheets(1).Columns(3).Row(cnt))
Sheets(1).Columns(4).Row(cnt).Copy_destination
(Sheets(1).Columns(4).Row(cnt))
Sheets(1).Columns(5).Row(cnt).Copy_destination
(Sheets(1).Columns(5).Row(cnt))
Sheets(1).Columns(6).Row(cnt).Copy_destination
(Sheets(1).Columns(6).Row(cnt))
End If
cnt = cnt + 1
Loop
End Sub
would like to copy all rows in dataset1 where the same identifier is in
dataset2 to a new worksheet.
Dataset 1 has 12500 entries and dataset 2 has approx 2500 entries.
If the copy procedure is very intensive would deleting the rows in
dataset1 where the identifier cannot be found in dataset2 be quicker?
I have had a go this morning but it takes too long to process. What
could i change to improve performance - alternatively is there simply a
better way.
Any suggestions would be gratefully received as this is my first go at
VB.
Thanks.
----------------------------------------------
Sub Main()
Dim cnt As Integer, target As String
cnt = 0
Do While Worksheets(2).Cells(cnt + 1, 1) <> ""
target = Worksheets(2).Cells(cnt + 1, 1)
Call MarkGoodRows(target)
cnt = cnt + 1
Loop
Call ClearUp
End Sub
Sub MarkGoodRows(target)
Dim cnt As Integer
cnt1 = 1
Do While Worksheets(1).Cells(cnt1, 1) <> ""
If Worksheets(1).Cells(cnt1, 1) = target Then
Sheets(1).Cells(cnt1, 8) = "Good Point"
Exit Sub
End If
cnt1 = cnt1 + 1
Loop
End Sub
Sub ClearUp()
Dim cnt As Integer
cnt = 1
Do While Sheets(1).Columns(1).Row(cnt) <> ""
If Sheets(1).Columns(8).Row(cnt) = "Good Point" Then
Sheets(1).Columns(1).Row(cnt).Copy_destination
(Sheets(1).Columns(1).Row(cnt))
Sheets(1).Columns(2).Row(cnt).Copy_destination
(Sheets(1).Columns(2).Row(cnt))
Sheets(1).Columns(3).Row(cnt).Copy_destination
(Sheets(1).Columns(3).Row(cnt))
Sheets(1).Columns(4).Row(cnt).Copy_destination
(Sheets(1).Columns(4).Row(cnt))
Sheets(1).Columns(5).Row(cnt).Copy_destination
(Sheets(1).Columns(5).Row(cnt))
Sheets(1).Columns(6).Row(cnt).Copy_destination
(Sheets(1).Columns(6).Row(cnt))
End If
cnt = cnt + 1
Loop
End Sub