ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find row with the same data like in another row (https://www.excelbanter.com/excel-programming/404067-find-row-same-data-like-another-row.html)

Bartosz

Find row with the same data like in another row
 
Hello All,

I try to learn VBA myself. But it stoped me:
Workbook A contain lot of rows. Workbook B contain one row which I need to
find in Worbook A. I try to find row in Workbook A which contain the same
data (First 20 columns contain data) like row 1 in Workbook B.

Thanks

Mike H.

Find row with the same data like in another row
 
Here is one way:

Sub FindRowInOther()
Dim Y as double
Dim Y as double
Dim Found as integer
dim Dataarray(20,1) as variant
sheets("Lookfordata").select
for X=1 to 20
dataarray(x,1)=cells(activecell.row,x).value
next

sheets("lookinData").select
x=1
do while true
if cells(x,1).value=empty then exit do 'assumes nothing in column A
ends search
found=0
for Y=1 to 20
if cells(x,Y).value=dataarray(x,1) then
found=Found+1
end if
end for
if found=20 then
msgbox("Found it! on row " & x)
cells(x,1).select
Ans=1
exit do
end if
x=x+1
Loop

if Ans=0 then
msgbox("Could not find your data!")
end if

End sub

"Bartosz" wrote:

Hello All,

I try to learn VBA myself. But it stoped me:
Workbook A contain lot of rows. Workbook B contain one row which I need to
find in Worbook A. I try to find row in Workbook A which contain the same
data (First 20 columns contain data) like row 1 in Workbook B.

Thanks


Bartosz

Find row with the same data like in another row
 
I made one change:
....was:
for Y=1 to 20
if cells(x,Y).value=dataarray(x,1) then


Should be: if cells(x,Y).value=dataarray(Y,1) then

Thanks anyway!!!

Mike H.

Find row with the same data like in another row
 
I think I had it right the first time I typed my initial reply. But
sometimes when i click "Post", I get a login-in screen which when I finally
remove it it says I am not authorized to upload a reply. I lose the text I
just typed and have to retype it if I forget to save the test outside of the
Message Box where I am typing this. But anyway, glad you can use it.

"Bartosz" wrote:

I made one change:
...was:
for Y=1 to 20
if cells(x,Y).value=dataarray(x,1) then


Should be: if cells(x,Y).value=dataarray(Y,1) then

Thanks anyway!!!


Alan Beban[_2_]

Find row with the same data like in another row
 
If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

Sub test12()
Dim rng1 As Range, rng2 As Range, iRow As Range
Set rng1 = Sheets("A").Range("A1:D20").Rows
Set rng2 = Sheets("B").Range("A1:D1")
For Each iRow In rng1
If RowsEqual(iRow, rng2) Then
MsgBox iRow.Row
Exit For
End If
Next
End Sub

Alan Beban

Bartosz wrote:
Hello All,

I try to learn VBA myself. But it stoped me:
Workbook A contain lot of rows. Workbook B contain one row which I need to
find in Worbook A. I try to find row in Workbook A which contain the same
data (First 20 columns contain data) like row 1 in Workbook B.

Thanks



All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com