Matching & importing

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 09:47 PM GMT

Question

In myworkbook, there is a sheet labelled as 'Port@C.P' in which C8:C20 has some shares names. those C8:C20 ranges are linked (only names are taken from the sheet) with another sheet named 'DSE'. In 'DSE' sheet Column G contains price of different shares and Column B contains Shares Name.

first i want to import close prices of my ranges (i.e c8:c20) into 'Port@C.P's Column H.

i want to clarify you. C8:C20 contains different shares name which were taken from 'DSE' sheet. you jut write vb code which will find C8:C20 ranges shares names in 'DSE' sheet's column B and put the close prices of those shares into 'Port@C.Ps Column H.

it's so simple for you as far i saw your ratings.

Answer

Sub getcloseprices() Dim shDest As Worksheet, shSrc As Worksheet Dim cell As Range, res As Variant, rSrc As Range Set shDest = Worksheets("Port@C.P") Set shSrc = Worksheets("DSE") With shSrc

 Set rSrc = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))

End With For Each cell In shDest.Range("C8:C20")

 res = Application.Match(cell, rSrc, 0)
 If Not IsError(res) Then
    cell.Offset(0, 5).Value = rSrc(res).Offset(0, 5).Value
 End If

Next End Sub

would be my guess at what you want.

I assume the data in sheet DSE starts in B2.

Advertisement

©2024 eLuminary LLC. All rights reserved.