ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through a column (https://www.excelbanter.com/excel-programming/337381-looping-through-column.html)

hudson40

Looping through a column
 

Hi

Its been a while since I've used excel and have a fairly easy question.
I'm trying to loop through a column (C). This column has either the word
'surplus' or 'deficit' in each cell. If the word is deficit I would like
to multiply the value in the preceeding col (B) by -1.

Any ideas greatly appreciated.


--
hudson40
------------------------------------------------------------------------
hudson40's Profile: http://www.excelforum.com/member.php...o&userid=24681
View this thread: http://www.excelforum.com/showthread...hreadid=396105


Tom Ogilvy

Looping through a column
 
Sub AA()
dim rng as Range, cell as Range
set rng = Range(cells(1,"C"),cells(rows.count,"C").End(xlup) )
for each cell in rng
if lcase(cell.value) = "deficit" then
if isnumeric(cell.offset(0,-1)) then
cell.offset(0,-1).value = cell.Offset(0,-1).value * (-1)
end if
end if
Next
End Sub

--
regards,
Tom Ogilvy

"hudson40" wrote in
message ...

Hi

Its been a while since I've used excel and have a fairly easy question.
I'm trying to loop through a column (C). This column has either the word
'surplus' or 'deficit' in each cell. If the word is deficit I would like
to multiply the value in the preceeding col (B) by -1.

Any ideas greatly appreciated.


--
hudson40
------------------------------------------------------------------------
hudson40's Profile:

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





All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com