Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Finding all matches in column B with datalist in column A

I have data from two sources being pasted into columns A, B and C of a new
spreadsheet. Column A contains the account number, B the customer name and C
a description of the transaction, including the customer name. I have a
routine which finds the first occurence and pasted the account number into
column D but I need it to continue and do so for all occurences. I am using
the following which runs perfectly for one project but needs modifying for
the curent one.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("FXDH").Activate
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Stop
Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
End If

Next

End Sub

How can I modify this to find all occurences?

Thanks,

Jim
--
Pops Jackson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Finding all matches in column B with datalist in column A

add the dim statement

Dim sAddr as String


Replace your search loop with this:

For Each cell In rngA
rng = rngb.Find(What:=cell.Value, _
After:=rngb(rngb.count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng is nothing Then
sAddr = rng.Address
do
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
set rng= rngB.FindNext(rng)
Loop while rng.Address < sAddr
End If
Next

--
Regards,
Tom Ogilvy

"Pops Jackson" wrote:

I have data from two sources being pasted into columns A, B and C of a new
spreadsheet. Column A contains the account number, B the customer name and C
a description of the transaction, including the customer name. I have a
routine which finds the first occurence and pasted the account number into
column D but I need it to continue and do so for all occurences. I am using
the following which runs perfectly for one project but needs modifying for
the curent one.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("FXDH").Activate
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Stop
Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
End If

Next

End Sub

How can I modify this to find all occurences?

Thanks,

Jim
--
Pops Jackson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Finding all matches in column B with datalist in column A

I made the changes but am getting "Object variable or With block variable not
set." error message at the line after "For each cell in rngA". I am
including the code below after the changes.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("Data").Activate

Dim sAddr As String
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

ActiveSheet.Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
ActiveSheet.Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
ActiveSheet.Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False

Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
rng = rngB.Find(What:=cell.Value, _
After:=rngB(rngB.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
Set rng = rngB.FindNext(rng)
Loop While rng.Address < sAddr
End If
Next

End Sub

Thanks

--
Pops Jackson


"Tom Ogilvy" wrote:

add the dim statement

Dim sAddr as String


Replace your search loop with this:

For Each cell In rngA
rng = rngb.Find(What:=cell.Value, _
After:=rngb(rngb.count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng is nothing Then
sAddr = rng.Address
do
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
set rng= rngB.FindNext(rng)
Loop while rng.Address < sAddr
End If
Next

--
Regards,
Tom Ogilvy

"Pops Jackson" wrote:

I have data from two sources being pasted into columns A, B and C of a new
spreadsheet. Column A contains the account number, B the customer name and C
a description of the transaction, including the customer name. I have a
routine which finds the first occurence and pasted the account number into
column D but I need it to continue and do so for all occurences. I am using
the following which runs perfectly for one project but needs modifying for
the curent one.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("FXDH").Activate
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Stop
Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
End If

Next

End Sub

How can I modify this to find all occurences?

Thanks,

Jim
--
Pops Jackson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Finding all matches in column B with datalist in column A

I have tried every way to add, modify etc to make this work but to no avail.
If anyone has an idea, I would truly appreciate hearing from you.

Thanks in advance,
--
Pops Jackson


"Pops Jackson" wrote:

I made the changes but am getting "Object variable or With block variable not
set." error message at the line after "For each cell in rngA". I am
including the code below after the changes.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("Data").Activate

Dim sAddr As String
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

ActiveSheet.Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
ActiveSheet.Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
ActiveSheet.Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
ActiveSheet.Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False

Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
rng = rngB.Find(What:=cell.Value, _
After:=rngB(rngB.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
Set rng = rngB.FindNext(rng)
Loop While rng.Address < sAddr
End If
Next

End Sub

Thanks

--
Pops Jackson


"Tom Ogilvy" wrote:

add the dim statement

Dim sAddr as String


Replace your search loop with this:

For Each cell In rngA
rng = rngb.Find(What:=cell.Value, _
After:=rngb(rngb.count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng is nothing Then
sAddr = rng.Address
do
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
set rng= rngB.FindNext(rng)
Loop while rng.Address < sAddr
End If
Next

--
Regards,
Tom Ogilvy

"Pops Jackson" wrote:

I have data from two sources being pasted into columns A, B and C of a new
spreadsheet. Column A contains the account number, B the customer name and C
a description of the transaction, including the customer name. I have a
routine which finds the first occurence and pasted the account number into
column D but I need it to continue and do so for all occurences. I am using
the following which runs perfectly for one project but needs modifying for
the curent one.

Sub abc()
Windows("FXDH.xls").Activate
Sheets("FXDH").Activate
Dim rngA As Range, rngB As Range
Dim rng As Range, cell As Range
Dim res As Variant
With Worksheets("Sheet1")

Range("D:D").Select
Selection.Copy
Sheets("Sheet1").Activate
Range("B1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Workbooks.Open ("T:\Fxbckoff\FXVolumeRpts\Customers.xls")
Sheets("qryCustomers").Activate
Range("A:A").Select
Selection.Copy
Windows("FXDH.xls").Activate
Sheets("Sheet1").Activate
Range("A1").Select
ActiveCell.PasteSpecial
Application.CutCopyMode = False
Stop
Set rngA = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
End With

For Each cell In rngA
res = Application.Match("*" & cell.Value & "*", rngB, 0)
If Not IsError(res) Then
Set rng = rngB(res)
rng.Font.Color = RGB(255, 0, 0)
rng.Font.Bold = True
rng.Offset(0, 1) = cell.Offset(0, 0).Value
End If

Next

End Sub

How can I modify this to find all occurences?

Thanks,

Jim
--
Pops Jackson

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
Maddening Dilemma - Compare each cell within column a to each cell in column b and find unique matches [email protected] Excel Worksheet Functions 66 May 1st 23 03:44 AM
column A matches f places the value from g in column b what funct Daryl Excel Worksheet Functions 2 November 15th 09 07:56 PM
Count cells w/values in column if the data in column a matches cri mdcgpw Excel Worksheet Functions 4 January 12th 09 11:55 PM
finding the largest value for a name in a column and then returningthe result from a different column [email protected] Excel Worksheet Functions 1 April 14th 08 10:08 AM
finding and reporting in column A, where a series of column reaches zero Gary Tamblyn Excel Programming 2 July 27th 03 12:00 PM


All times are GMT +1. The time now is 06:21 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"