Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default (VBA Function ?) Lookup value and copy it into antoher worksheet

Hi all,

Who can help me with this issue. I have 2 worksheets with specific data
in it (Each Sheet contains about +/- 2000 records) and I would like to
create a very special lookup function. (With copying cells if possible)
To illustrate the problem please take a look at this example:

For Example:

Sheet1:

NAME REFNUMBER COLOR
John 1
Michael 1
Kenneth 2
Keith 1

Sheet 2:

REFNUMBER COLOR
1 Green
1 Green-Blue
1 Green-Yellow
2 Black
2 Black-Yellow
2 Black-Purple
2 Black-Grey
3 Pink

I want to create a lookup function wich will look-up the reference
number in Sheet2 and paste all the corresponding colors value in sheet
1.

So Sheet1 should become:

NAME REFNUMBER COLOR
John 1 Green
Green-Blue
Green-Yellow
Michael 1 Green
Green-Blue
Green-Yellow
Kenneth 2 Black
Black-Yellow
Black-Purple
Black-Grey
Keith 1 Green
Green-Blue
Green-Yellow

Is it possible to crate such a function (with or without VBA Code)

Thanks in advance!

Kind Regards,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default (VBA Function ?) Lookup value and copy it into antoher worksheet

Sub ABC()
Dim rng As Range
Dim i As Long, refNum As Long
Dim j As Long, cell As Range
With Worksheets("Sheet2")
Set rng = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
i = 2
With Worksheets("Sheet1")
Do
refNum = .Cells(i, 2)
cnt = Application.CountIf(rng, refNum)
If cnt < 0 Then
If cnt 1 Then _
.Cells(i + 1, 2).Resize(cnt - 1, 1).EntireRow.Insert
j = i
For Each cell In rng
If cell.Value = refNum Then
.Cells(j, 3).Value = cell.Offset(0, 1).Value
j = j + 1
End If
Next
Else
cnt = 1
End If
i = i + cnt
Loop While Not IsEmpty(.Cells(i, 2))
End With

End Sub

--
Regards,
Tom Ogilvy



wrote in message
ups.com...
Hi all,

Who can help me with this issue. I have 2 worksheets with specific data
in it (Each Sheet contains about +/- 2000 records) and I would like to
create a very special lookup function. (With copying cells if possible)
To illustrate the problem please take a look at this example:

For Example:

Sheet1:

NAME REFNUMBER COLOR
John 1
Michael 1
Kenneth 2
Keith 1

Sheet 2:

REFNUMBER COLOR
1 Green
1 Green-Blue
1 Green-Yellow
2 Black
2 Black-Yellow
2 Black-Purple
2 Black-Grey
3 Pink

I want to create a lookup function wich will look-up the reference
number in Sheet2 and paste all the corresponding colors value in sheet
1.

So Sheet1 should become:

NAME REFNUMBER COLOR
John 1 Green
Green-Blue
Green-Yellow
Michael 1 Green
Green-Blue
Green-Yellow
Kenneth 2 Black
Black-Yellow
Black-Purple
Black-Grey
Keith 1 Green
Green-Blue
Green-Yellow

Is it possible to crate such a function (with or without VBA Code)

Thanks in advance!

Kind Regards,



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LOOKUP worksheet function F. Lawrence Kulchar Excel Discussion (Misc queries) 7 July 27th 08 05:47 PM
Lookup returning value from antoher column in same row (Text!) Cube Zombie Excel Discussion (Misc queries) 3 February 15th 08 08:19 PM
copy subtotal value only - also can be lookup from other worksheet BB Excel Discussion (Misc queries) 1 June 30th 06 09:12 AM
Prtinting antoher worksheet Glenn Excel Programming 1 April 12th 05 05:48 PM
vba code for lookup worksheet function Binoy[_2_] Excel Programming 1 December 13th 03 07:47 PM


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"