Need to find a static value in a cell and then subtract from adjacent cell

J

jihaan

Hello

I'm trying to write a macro that will look at a series of cells for a specifi
word. If the word it is found, it will subtract the value from the cel
adjacent to the cell it found the word in

For instance, loop through cells E32 - E42. If word, "Paul" is foun
in cell E32, subtract value in cell F32 from cell D25. Otherwise if word
"Paul" is found in cell E33, subtract value in cell F33 from cell D25
If "Paul" is found in E32 and E33, subtract values in F32 and F3
from D25

D25 is static. The value to subtract is dynamic based on the values in colum
E

Please help

Thanks
Jihaan
 
A

Auric__

jihaan said:
I'm trying to write a macro that will look at a series of cells for a
specific word. If the word it is found, it will subtract the value
from the cell adjacent to the cell it found the word in.

For instance, loop through cells E32 - E42. If word, "Paul" is found
in cell E32, subtract value in cell F32 from cell D25. Otherwise if
word, "Paul" is found in cell E33, subtract value in cell F33 from cell
D25. If "Paul" is found in E32 and E33, subtract values in F32 and F33
from D25.

D25 is static. The value to subtract is dynamic based on the values in
column E.

You practically wrote the code yourself:

For n = 32 To 42
If InStr(Cells(n, 5).Value, "Paul") Then
Range("D25").Value = Range("D25").Value - Cells(n, 6).Value
End If
Next
 

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

Top