ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problem with code (https://www.excelbanter.com/excel-programming/284565-problem-code.html)

gareth

problem with code
 
I need to use the following code on a column containing
formula. It works if there are just values in the range
but my range has formula in it.

Sub tester()
For Each cell In Range("B2:B20")
If cell.Value 0 Then
cell.Offset(0, -1).Value = "Yes"
End If
Next
End Sub

Thanks in advance.

Gareth

Tom Ogilvy

problem with code
 
The code you show should work whether there are formula or not. The only
problem I can see if is the cell value is text, then you might have a
problem with the if statement.

Sub tester()
For Each cell In Range("B2:B20")
if not isempty(cell.Value) then
if isnumeric(cell.Value) then
If cell.Value 0 Then
cell.Offset(0, -1).Value = "Yes"
End if
end if
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"gareth" wrote in message
...
I need to use the following code on a column containing
formula. It works if there are just values in the range
but my range has formula in it.

Sub tester()
For Each cell In Range("B2:B20")
If cell.Value 0 Then
cell.Offset(0, -1).Value = "Yes"
End If
Next
End Sub

Thanks in advance.

Gareth





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

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