Macro to Search a list and enter data into a cell on a diffrent worksheet if Criteria is met

beerw0lf

Board Regular
Joined
Mar 7, 2006
Messages
103
Hello All,
I am in need of some assistance once again. I have 2 worksheets. "Data" & "List". In the "Data" sheet column "H" contains model numbers. In the "List" sheet column "A" contain model numbers and column "C" contaims family names. I would like a macro that searches through column "H" in the "Data" sheet and if a model number matches column "A" of the "List" sheet I want the data in column "C" of the "List" sheet copied over to column "F" of the "Data" sheet.

I hope this makes sense.

Any and all help is greatly apprectiated.

Many Thanks!!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi beerw0lf,

Try this

Code:

Sub coptdata()
r = ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Row
dr = Workbooks("Data.xls").Sheets(1).Range("H65536").End(xlUp).Row
For a = 1 To r
x = ThisWorkbook.Sheets(1).Cells(a, 1).Text
With Workbooks("Data.xls").Sheets(1)
For b = 1 To dr
If .Cells(b, 8).Text = x Then
.Cells(a, 6) = ThisWorkbook.Sheets(1).Cells(b, 3)
End If
Next b
End With
Next a
End Sub


Code:

Regards

ColinKJ
 
Upvote 0

beerw0lf

Board Regular
Joined
Mar 7, 2006
Messages
103
Thanks for the reply ColinKJ. This macro is not working. I'm a little confused. You have "Data.xls" in the macro. I have 2 worksheets called "Data" and "List". The macro is hanging up on the line:

dr = Workbooks("Data.xls").Sheets(1).Range("H65536").End(xlUp).Row


Thanks
 
Upvote 0

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi beerw0lf,

Sorry, I should have said, the macro should be in the List.xls workbook.

Reference in the macro to "ThisWorkBook" is List.xls.

If you are running the macro in a seperate workbook, change "ThisWorkBook" to "Workbooks("List.xls")"

ColinKJ
 
Upvote 0

beerw0lf

Board Regular
Joined
Mar 7, 2006
Messages
103
ADVERTISEMENT
This macro will be running in just 1 workbook "ST Family.xls". Within this workbook I will be working with 2 worksheets "Data" and "List". I think I may be missing something here and not understanding the macro.

Thanks
 
Upvote 0

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi beerw0lf,

Sorry again, I'm having a bad day, it's not your understanding, it's mine.

I was reading your post as you having two Workbooks, where in fact you have two worksheets in the same workbook, sorry.

Try this

Code:

Sub coptdata()
r = Sheets("List").Range("A65536").End(xlUp).Row
dr = Sheets("Data").Range("H65536").End(xlUp).Row
For a = 1 To r
x = Sheets("List").Cells(a, 1).Text
With Sheets("Data")
For b = 1 To dr
If .Cells(b, 8).Text = x Then
.Cells(a, 6) = Sheets("List").Cells(b, 3)
End If
Next b
End With
Next a
End Sub

Code:

Regards

ColinKJ
 
Upvote 0

beerw0lf

Board Regular
Joined
Mar 7, 2006
Messages
103
ADVERTISEMENT
The macro does not error but it also does not seem to accomplish its task. Nothing seems to be copying over.
 
Upvote 0

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi again beerw0lf,

We're not having a good are we!! both of us I mean.

If you can send me a priate mail with an email address, I'll send you the test sheet I'm running in.

Regards

ColinKJ
 
Upvote 0

beerw0lf

Board Regular
Joined
Mar 7, 2006
Messages
103
Hello ColinJK,
I believe this is working now. I got the list second hand and apparently there was no matching data beween the list and the data worksheets. As soome as I coppied over matching data it seems to work. Thanks so much for you help with this it is greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,195,680
Messages
6,011,126
Members
441,586
Latest member
rodsin76

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top