Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default find range question

Dear experts,
I need to compare 2 ranges of data by a concatenation of cells (for both). I
have the following code

For i = 1 To 10
Set f = sha.Range("a" & i & ":d" & i).Find(what:=shb.Range("a1:d1"),
lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then MsgBox f.Address
Next i

But it does not do what I want as it just stops the comparison at the first
cell value, it does not concatenate the values of the range.

Could you please help me?

Many thanks in advance.
Kind regards

--
Valeria
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default find range question

The below macro will search for Sheet2 Range("A1:D1") in
Sheet1.Range("A1:D10") and if found displays the row number in Sheet1...

Sub Macro()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim varFound As Variant, varSearch As Variant
Dim strAddress As String, blnFound As Boolean, cell As Range


Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set varSearch = ws2.Range("A1:D1")

With ws1.Range("A1:A10")
Set varFound = .Find(varSearch(1), LookIn:=xlValues)
If Not varFound Is Nothing Then
strAddress = varFound.Address
Do
blnFound = True
For Each cell In varSearch
If cell.Value < ws1.Cells(varFound.Row, cell.Column) Then
blnFound = False: Exit For
End If
Next
If blnFound = True Then MsgBox varFound.Row: Exit Sub
Set varFound = .FindNext(varFound)
Loop While Not varFound Is Nothing And _
varFound.Address < strAddress
End If
End With

End Sub


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I need to compare 2 ranges of data by a concatenation of cells (for both). I
have the following code

For i = 1 To 10
Set f = sha.Range("a" & i & ":d" & i).Find(what:=shb.Range("a1:d1"),
lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then MsgBox f.Address
Next i

But it does not do what I want as it just stops the comparison at the first
cell value, it does not concatenate the values of the range.

Could you please help me?

Many thanks in advance.
Kind regards

--
Valeria

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default find range question

it works beautifully, thank you very much!
--
Valeria


"Jacob Skaria" wrote:

The below macro will search for Sheet2 Range("A1:D1") in
Sheet1.Range("A1:D10") and if found displays the row number in Sheet1...

Sub Macro()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim varFound As Variant, varSearch As Variant
Dim strAddress As String, blnFound As Boolean, cell As Range


Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set varSearch = ws2.Range("A1:D1")

With ws1.Range("A1:A10")
Set varFound = .Find(varSearch(1), LookIn:=xlValues)
If Not varFound Is Nothing Then
strAddress = varFound.Address
Do
blnFound = True
For Each cell In varSearch
If cell.Value < ws1.Cells(varFound.Row, cell.Column) Then
blnFound = False: Exit For
End If
Next
If blnFound = True Then MsgBox varFound.Row: Exit Sub
Set varFound = .FindNext(varFound)
Loop While Not varFound Is Nothing And _
varFound.Address < strAddress
End If
End With

End Sub


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I need to compare 2 ranges of data by a concatenation of cells (for both). I
have the following code

For i = 1 To 10
Set f = sha.Range("a" & i & ":d" & i).Find(what:=shb.Range("a1:d1"),
lookat:=xlWhole, LookIn:=xlValues)
If Not f Is Nothing Then MsgBox f.Address
Next i

But it does not do what I want as it just stops the comparison at the first
cell value, it does not concatenate the values of the range.

Could you please help me?

Many thanks in advance.
Kind regards

--
Valeria

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
What is SearchFormat parameter in cell.Find / Range.Find do? Alex Excel Programming 0 April 16th 09 02:25 PM
Find End in Undefined Range Select Range Trim SteveT Excel Programming 4 November 29th 07 06:54 PM
Find the POSITION IN A RANGE of text in a string that matches value(s) in a range Cornell1992 Excel Programming 0 March 14th 06 07:19 PM
Find dates in a range; then sum values in that range by a criteria Anders Excel Discussion (Misc queries) 4 October 21st 05 03:41 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM


All times are GMT +1. The time now is 02:31 PM.

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"