ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Matching a number from another sheet and copying a related value (https://www.excelbanter.com/excel-programming/402479-matching-number-another-sheet-copying-related-value.html)

Heldy

Matching a number from another sheet and copying a related value
 
Hi all,

I'm pretty new to the VB world and have a macro question.

I'm trying to take a part number from one database in excel and then search
for the matching part number in a different workbook. Once that value is
matched or found, then I need to copy the price of that part back to the
orginal excel sheet. This needs to be done for multiple part numbers, well
until it hits a blank.

I have tried a few things, but I just can't get it right. My problem is how
to move to the next cell and select the price cell once the part number is
found.

Does anyone have some example code to do this? Anything would help. Thanks

Gary''s Student

Matching a number from another sheet and copying a related value
 
This sub looks for three part numbers. There is no error handler if the part
numbers can't be found, but it should give you a start:

Sub fetchit()
partnumber = Array(100, 101, 102)
For i = 0 To 2
pn = partnumber(i)
Windows("database.xls").Activate
For j = 1 To 1000
If Cells(j, "A").Value = pn Then
Cells(j, "B").Copy
Exit For
End If
Next
Windows("original.xls").Activate
Cells(i + 1, "A").Select
ActiveSheet.Paste
Next
End Sub

--
Gary''s Student - gsnu200761


"Heldy" wrote:

Hi all,

I'm pretty new to the VB world and have a macro question.

I'm trying to take a part number from one database in excel and then search
for the matching part number in a different workbook. Once that value is
matched or found, then I need to copy the price of that part back to the
orginal excel sheet. This needs to be done for multiple part numbers, well
until it hits a blank.

I have tried a few things, but I just can't get it right. My problem is how
to move to the next cell and select the price cell once the part number is
found.

Does anyone have some example code to do this? Anything would help. Thanks



All times are GMT +1. The time now is 04:39 PM.

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