ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Locate negative number (https://www.excelbanter.com/excel-worksheet-functions/175657-locate-negative-number.html)

BurtArkin

Locate negative number
 
I have a column of numbers (based on an underlying formula), starting
positive at the top. Somewhere in the column, a number becomes negative.
How, using VB code, do I search for that cell, where the number =<0. Once
the cell is located, I want to then alter the formula of the cell to its
left. I would appreciate any help I get. Thanks
--
Burt

Mike H

Locate negative number
 
Hi,

You didn't say what you wanted the formula altered to so this simply enter
123 in the appropriate cell

Sub ordinate()
Set myrange = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each c In myrange
If c.Value < "" And c.Value <= 0 Then
c.Offset(0, -1).Value = 123 ' Do what you want
Exit Sub
End If
Next


Mike

"BurtArkin" wrote:

I have a column of numbers (based on an underlying formula), starting
positive at the top. Somewhere in the column, a number becomes negative.
How, using VB code, do I search for that cell, where the number =<0. Once
the cell is located, I want to then alter the formula of the cell to its
left. I would appreciate any help I get. Thanks
--
Burt


BurtArkin

Locate negative number
 
Thank you so much for your quick response. I will play with it, and, if
there are any problems (I'm not too swift!), I'll get back to you.
--
Burt


"Mike H" wrote:

Hi,

You didn't say what you wanted the formula altered to so this simply enter
123 in the appropriate cell

Sub ordinate()
Set myrange = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each c In myrange
If c.Value < "" And c.Value <= 0 Then
c.Offset(0, -1).Value = 123 ' Do what you want
Exit Sub
End If
Next


Mike

"BurtArkin" wrote:

I have a column of numbers (based on an underlying formula), starting
positive at the top. Somewhere in the column, a number becomes negative.
How, using VB code, do I search for that cell, where the number =<0. Once
the cell is located, I want to then alter the formula of the cell to its
left. I would appreciate any help I get. Thanks
--
Burt



All times are GMT +1. The time now is 11:57 AM.

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