Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for a value and copy to different sheet

Status
Not open for further replies.

robcarr

Programmer
May 15, 2002
633
GB
Dear All,

I am trying to change some coding that was given to me before to no avail, I am trying to do the following, check each value in column A on daily data, and find the location of this value in sheet1, when it finds the value in sheet1 it will copy the value in column B on daily data for that item, and paste the value in the farmost column in sheet1(sheet1 columns are always complete block of data, but rows can have blanks, but would be no more than 250 rows), but I am getting confused with the coding, daily data sheet values in column A will always appear on sheet1.

Coding


Sub copythedata()
Dim Match As Object
Dim i As Integer

i = 1
With Worksheets("Sheet1").UsedRange.Columns(1)
Do
Set Match = .Find(Worksheets("Daily Data").Cells(i, 1), LookAt:=xlWhole)
If Not Match Is Nothing Then Worksheets("Daily Data").Cells(Match.Row, 2) _
= Worksheets("sheet1").Cells(i, 15)
i = i + 1
Loop While Not Len(Worksheets("daily Data").Cells(i, 1)) = 0
End With

Application.ScreenUpdating = True

End Sub

Any help will be greatly appreciated, I am sure the coding works as I used it on a similar example but cannot recreate it again.

Thanks in advance Thanks Rob.[yoda]
 
Rob,

Assuming the above is the code you are using, what results are you getting when you execute?

MM
 
the codiing doesnt seem to do anything I am getting lost with it, i can run it and no changes appear on the sheets, also I need to alter slightly or find better way to do it.

Thanks Rob.[yoda]
 
Robcarr,
Try this variation of your code and see if it does what you want.

Sub copythedata()
Dim Match As Object
Dim i As Integer
Dim xx
i = 1
With Worksheets("main").UsedRange.Columns(1)
Do
Set Match = .Find(Worksheets("Daily Data").Cells(i, 1), LookAt:=xlWhole)
If Not Match Is Nothing Then
Worksheets("Daily Data").Select
Cells(i, 2).Select
xx = ActiveCell.Value

Worksheets("main").Select
Cells(i, 15).Select
ActiveCell.Value = xx
End If
i = i + 1
Loop While Not Len(Worksheets("daily Data").Cells(i, 1)) = 0
End With

Application.ScreenUpdating = True

End Sub

Andrew 299
 
robcarr,

I got the same results with the above code (I added the end if statement). I did switch the line in the if statement from:

Worksheets("Daily Data").Cells(Match.Row, 2) _
= Worksheets("sheet1").Cells(i, 15)

to:

Worksheets("sheet1").Cells(i, 15) _
= Worksheets("Daily Data").Cells(Match.Row, 2)

and it seemed to work...

Hope this is helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top