Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


On sheet1 I have a continually updating list. A:A contains dates, B:B
and C:C contain ID numbers. Some dates will be duplicated and some ID
numbers will be duplicated. On sheet2 I have a calendar and date box.
When the user enters a date into sheet2!B1 I need a5:c? to generate all
the lines from sheet1 that have the same date.
For example:
sheet2!B1 = 6/1/06, sheet2!a5 should say 6/1/06, sheet2!b5 should say
1234 and sheet2!c5 should say 9876. This should repeat all the way
down until there are no more dates on sheet1 that match sheet2!b1.

I hope this makes sense. Please let me know if I need to elaborate or
show a detailed example. Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Lookup or Index or Match, not sure.

Try this. First right click the "Sheet2" tab in excel and click "View
Code" and paste this in:

Private Sub Worksheet_Change(ByVal Target As Range)
Call FindMatch(Target)
End Sub

Then you will need to insert a new module in the VB editor and paste
this code:

Sub FindMatch(Target As Range)
Dim DateSearch As String
Dim nRow As Double 'Next Row to paste on
Dim Cnt As Double
If Not Target.Address = "$B$1" Then Exit Sub
Application.ScreenUpdating = False
DateSearch = Target.Value
If DateSearch < "" Then
Range("A5").Select
If Range("A5").Value = "" Then
nRow = 5
ElseIf Range("A6").Value = "" Then
nRow = 6
Else
nRow = Selection.End(xlDown).Row
End If
Sheets(1).Activate
Range("A1").Activate
For Cnt = 1 To Selection.End(xlDown).Row
If Cells(Cnt, 1).Value = DateSearch Then
Range(Cells(Cnt, 1), Cells(Cnt, 3)).Copy
Sheets(2).Activate
Cells(nRow, 1).PasteSpecial xlPasteAll
nRow = nRow + 1
Sheets(1).Activate
End If
Next
End If
Sheets(2).Activate
Application.ScreenUpdating = True
End Sub

Post back if it doesn't work

HTH

Die_Another_Day


ForSale wrote:
On sheet1 I have a continually updating list. A:A contains dates, B:B
and C:C contain ID numbers. Some dates will be duplicated and some ID
numbers will be duplicated. On sheet2 I have a calendar and date box.
When the user enters a date into sheet2!B1 I need a5:c? to generate all
the lines from sheet1 that have the same date.
For example:
sheet2!B1 = 6/1/06, sheet2!a5 should say 6/1/06, sheet2!b5 should say
1234 and sheet2!c5 should say 9876. This should repeat all the way
down until there are no more dates on sheet1 that match sheet2!b1.

I hope this makes sense. Please let me know if I need to elaborate or
show a detailed example. Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


Works great! Thanks.

What should I change if I want the data to copy to a different locatio
on sheet2? I want the data to start in B6 now on sheet2.

Thanks

--
ForSal
-----------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...fo&userid=1189
View this thread: http://www.excelforum.com/showthread.php?threadid=54923

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Lookup or Index or Match, not sure.

Sub FindMatch(Target As Range)
Const StartCell As String = "B6"
Dim SearchVal
Dim cell As Range
Dim i As Long
Dim FirstAddress As String

If Not Target.Address = "$B$1" Then Exit Sub
Application.ScreenUpdating = False
SearchVal = Range("B1").Text
With Worksheets("Sheet1").Range("A:A")
Set cell = .Find(SearchVal, LookIn:=xlValues)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
cell.Resize(1, 4).Copy Range(StartCell).Offset(i, 0)
i = i + 1
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address < FirstAddress
End If
End With

Application.ScreenUpdating = True
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ForSale" wrote in
message ...

Works great! Thanks.

What should I change if I want the data to copy to a different location
on sheet2? I want the data to start in B6 now on sheet2.

Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile:

http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Lookup or Index or Match, not sure.

Bob, I like your code but I don't understand how it is copying into
sheet2 in this line:

cell.Resize(1, 4).Copy Range(StartCell).Offset(i, 0)

can you please explain this for me.

Also should we add LookAt:=xlWhole to the .find statement to make sure
that it doesn't grab cells containing the partial data? for example:

search for "1/1/06"
if cell contained this "11/1/06" it would get copied with your code.

Thx

Die_Another_Day

Bob Phillips wrote:
Sub FindMatch(Target As Range)
Const StartCell As String = "B6"
Dim SearchVal
Dim cell As Range
Dim i As Long
Dim FirstAddress As String

If Not Target.Address = "$B$1" Then Exit Sub
Application.ScreenUpdating = False
SearchVal = Range("B1").Text
With Worksheets("Sheet1").Range("A:A")
Set cell = .Find(SearchVal, LookIn:=xlValues)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
cell.Resize(1, 4).Copy Range(StartCell).Offset(i, 0)
i = i + 1
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address < FirstAddress
End If
End With

Application.ScreenUpdating = True
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ForSale" wrote in
message ...

Works great! Thanks.

What should I change if I want the data to copy to a different location
on sheet2? I want the data to start in B6 now on sheet2.

Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile:

http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Lookup or Index or Match, not sure.

It assumes that Sheet2 is active. The Find looks across to Sheet1 (without
activating it), gets the data, and copies it that activesheet (Sheet2).

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Die_Another_Day" wrote in message
oups.com...
Bob, I like your code but I don't understand how it is copying into
sheet2 in this line:

cell.Resize(1, 4).Copy Range(StartCell).Offset(i, 0)

can you please explain this for me.

Also should we add LookAt:=xlWhole to the .find statement to make sure
that it doesn't grab cells containing the partial data? for example:

search for "1/1/06"
if cell contained this "11/1/06" it would get copied with your code.

Thx

Die_Another_Day

Bob Phillips wrote:
Sub FindMatch(Target As Range)
Const StartCell As String = "B6"
Dim SearchVal
Dim cell As Range
Dim i As Long
Dim FirstAddress As String

If Not Target.Address = "$B$1" Then Exit Sub
Application.ScreenUpdating = False
SearchVal = Range("B1").Text
With Worksheets("Sheet1").Range("A:A")
Set cell = .Find(SearchVal, LookIn:=xlValues)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
cell.Resize(1, 4).Copy Range(StartCell).Offset(i, 0)
i = i + 1
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address <

FirstAddress
End If
End With

Application.ScreenUpdating = True
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ForSale" wrote

in
message ...

Works great! Thanks.

What should I change if I want the data to copy to a different

location
on sheet2? I want the data to start in B6 now on sheet2.

Thanks.


--
ForSale


------------------------------------------------------------------------
ForSale's Profile:

http://www.excelforum.com/member.php...o&userid=11896
View this thread:

http://www.excelforum.com/showthread...hreadid=549232




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


Thanks to both. Unfortunately I don't understand most of this, so I'
having a hard time altering it to fit my sheet.

On sheet1, there are 10 columns, A:K. You have helped me move A:
over, now I also need to move F:K also.

In other words, I need sheet1!A:B to copy to sheet2!A:B, then I nee
sheet1!F:K to copy to sheet2!E:J.

Thanks again

--
ForSal
-----------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...fo&userid=1189
View this thread: http://www.excelforum.com/showthread.php?threadid=54923

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


Also, can we throw in a clear of some sort. Right now if I run this fo
6/1/06 it puts three results into sheet2. If I change the date t
6/2/06 (which only has two matches), sheet2 shows two with 6/2/06 an
then one with 6/1/06.

I think we need to put a clear type thing in there somewhere so i
starts fresh each time.

Thanks

--
ForSal
-----------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...fo&userid=1189
View this thread: http://www.excelforum.com/showthread.php?threadid=54923

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


Bob,
With your code I have figured out how to move all of the cells that I
need. I am still having trouble clearing sheet2 before running
FindMatch. I have named the range that needs to be cleared 'field'.

Any ideas?

Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Lookup or Index or Match, not sure.

If you post the code that you have now that moves all the correct data, I
will add the clear.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ForSale" wrote in
message ...

Bob,
With your code I have figured out how to move all of the cells that I
need. I am still having trouble clearing sheet2 before running
FindMatch. I have named the range that needs to be cleared 'field'.

Any ideas?

Thanks.


--
ForSale
------------------------------------------------------------------------
ForSale's Profile:

http://www.excelforum.com/member.php...o&userid=11896
View this thread: http://www.excelforum.com/showthread...hreadid=549232





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup or Index or Match, not sure.


Sub FindMatch(Target As Range)
Const StartCell As String = "B6"
Dim SearchVal
Dim cell As Range
Dim i As Long
Dim FirstAddress As String

If Not Target.Address = "$B$1" Then Exit Sub
Application.ScreenUpdating = False
SearchVal = Range("B1").Text
With Worksheets("Data Entry").Range("A:A")
Set cell = .Find(SearchVal, LookIn:=xlValues)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
cell.Resize(1, 10).Copy Range(StartCell).Offset(i, 0)
i = i + 1
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address < FirstAddress
End If
End With

Application.ScreenUpdating = True
End Sub





Bob Phillips Wrote:
If you post the code that you have now that moves all the correct data
I
will add the clear.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ForSale" wrot
in
message ...

Bob,
With your code I have figured out how to move all of the cells tha

I
need. I am still having trouble clearing sheet2 before running
FindMatch. I have named the range that needs to be cleared 'field'.

Any ideas?

Thanks.


--
ForSale


------------------------------------------------------------------------
ForSale's Profile:

http://www.excelforum.com/member.php...o&userid=11896
View this thread

http://www.excelforum.com/showthread...hreadid=549232


--
ForSal
-----------------------------------------------------------------------
ForSale's Profile: http://www.excelforum.com/member.php...fo&userid=1189
View this thread: http://www.excelforum.com/showthread.php?threadid=54923

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 / Index/Match Joe Excel Worksheet Functions 3 February 11th 10 01:12 PM
Match or Index or Lookup??? Qld Help.. New Users to Excel 4 July 21st 08 10:45 PM
Lookup, index, match? Kikuchisawa Excel Worksheet Functions 1 March 10th 08 09:14 PM
LOOKUP, MATCH, INDEX? bob Excel Worksheet Functions 13 June 6th 07 04:26 AM
lookup/index/match - help! Ellen G. Excel Discussion (Misc queries) 3 February 13th 06 09:10 PM


All times are GMT +1. The time now is 07:41 PM.

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

About Us

"It's about Microsoft Excel"