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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Values

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello:

I new to VBA but looking to do the following. I have a worksheet which has the below list:

Name TodayDate Value
ABC 20/05/02 102
GUY 20/05/02 121
DIR 20/05/02 878

I have another workbook that has ABC, GUY, DIR in row 3. So:

Date DIR ABC GUY
18/05/02 154 545 454
19/05/02 455 124 432
20/05/02

I want some code whereby it will go through the initial list and find the match (for column Name, eg: ABC = ABC) in the second workbook then paste the information in Value under that list but for today's date. So, for the date 20/05/02 you would see:

Date DIR ABC GUY
18/05/02 154 545 454
19/05/02 455 124 432
20/05/02 878 102 121


Thks:
Keith
 
I can put all the data in one workbook but different worksheets if that makes it easier.
 
dope ! jsut got an example for you and realised its the wrong way round,

hopefully this will give you and idea though

two worksheets named sheeta and sheetb respectivily

sheeta contains the following starging in cell B2

NAME DATE VALUE
ABC 20/05/02
GUY 20/05/02
DIR 20/05/02

Sheetb has the following again starting on cell B2

Date DIR ABC GUY
18/05/02 154 545 454
19/05/02 455 124 432
20/05/02 878 102 121

then your code looks like this

Sub Bob()
'gratuitis plug for website
Dim Arr1(), Arr2() As Variant
Dim Int1, int2, int3 As Integer
Dim Strfnd As String
Dim Myvalue As Integer
Dim dttofnd

Arr1() = Sheets("sheeta").Range("B2:E5").Value
Arr2() = Sheets("sheetb").Range("B2:E5").Value

Int1 = 2

Do Until Int1 = UBound(Arr1()) + 1

Strfnd = Arr1(Int1, 1)
dttofnd = Arr1(Int1, 2)
int2 = 2
Do Until int2 = UBound(Arr2()) + 1
If Arr2(int2, 1) = dttofnd Then
int3 = 2
Do Until int3 = 4
If Arr2(1, int3) = Strfnd Then

Arr1(Int1, 3) = Arr2(int2, Int1)

End If
int3 = int3 + 1
Loop


End If


int2 = int2 + 1

Loop



Int1 = Int1 + 1

Loop
Sheets("sheeta").Range("B2:E5").Value = Arr1()


End Sub



if you need help to turn it back round just shout
 
If you can insert another column to concatenate date and 3 letter code eg
DIR20/5/02

you could use vlookup - no code needed at all

HTH
Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top