finding values

  • Thread starter Thread starter italiavb
  • Start date Start date
I

italiavb

I have 5 columns of information. Column A and C are text; B and D are
numbers. I need to match a text string in column C to the same string in
column A. When a match is found, subtract the value in the adjacent cell in
column D from the value in column B. put the result in column E. Can anyone
help?
 
Is this row by row - so if there is a match it is on the same row. If not,
then which row in column E should be used? Adjacent to the cell in A or C.
 
C...think you can make this happen?

Tom Ogilvy said:
Is this row by row - so if there is a match it is on the same row. If
not,
then which row in column E should be used? Adjacent to the cell in A or
C.
 
Sub CheckForMatches()
Dim rngA as Range, rngB as Range, rngC as Range
Dim rngD as Range, rngE as Range
Dim cell as Range, res as Variant
with worksheets("Sheet1")
set rngA = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
set rngC = .Range(.Cells(1,3),.Cells(rows.count,3).End(xlup))
End with
for each cell in rngC
res = Application.Match(cell.Value, rngA,0)
if not iserror(res) then
set rngB = rngA(res).Offset(0,1)
set rngE = cell.offset(0,2)
set rngD = cell.offset(0,1)
if isnumeric(rngB.Value) and _
isnumeric(rngD.Value) then
rngE.value = rngB.Value - rngD.Value
End if
End if
Next
End sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top