ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with Loop (https://www.excelbanter.com/excel-programming/301599-help-loop.html)

JMay

Help with Loop
 
All cells in Column C are being filled with "LOW";
How do I fix it so that only 0's in Column B paste "LOW" in Column C,
TIA,

Sub TryAgain()
Dim myCell As Range, rng As Range
Set rng = Range("B1:B10")
For Each myCell In rng
If myCell = 0 Then
rng.Offset(, 1).Value = "LOW"
End If
Next myCell
End Sub



Tom Ogilvy

Help with Loop
 
Sub TryAgain()
Dim myCell As Range, rng As Range
Set rng = Range("B1:B10")
For Each myCell In rng
If myCell = 0 and not isempty(mycell) Then '<==
myCell.Offset(0, 1).Value = "LOW" '<===
End If
Next myCell
End Sub

--
Regards,
Tom Ogilvy

"JMay" wrote in message news:OyWzc.382$WI2.162@lakeread05...
All cells in Column C are being filled with "LOW";
How do I fix it so that only 0's in Column B paste "LOW" in Column C,
TIA,

Sub TryAgain()
Dim myCell As Range, rng As Range
Set rng = Range("B1:B10")
For Each myCell In rng
If myCell = 0 Then
rng.Offset(, 1).Value = "LOW"
End If
Next myCell
End Sub





Bob Phillips[_6_]

Help with Loop
 
JMay,

not tersted, but hope okay

Sub TryAgain()
Dim myCell As Range, rng As Range
Set rng = Range("B1:B10")
For Each myCell In rng
If myCell.Value = 0 And myCell.Value < "" Then
myCell.Offset(, 1).Value = "LOW"
End If
Next myCell
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"JMay" wrote in message news:OyWzc.382$WI2.162@lakeread05...
All cells in Column C are being filled with "LOW";
How do I fix it so that only 0's in Column B paste "LOW" in Column C,
TIA,

Sub TryAgain()
Dim myCell As Range, rng As Range
Set rng = Range("B1:B10")
For Each myCell In rng
If myCell = 0 Then
rng.Offset(, 1).Value = "LOW"
End If
Next myCell
End Sub





Berend Botje[_17_]

Help with Loop
 
Sub TryAgain()

Dim myCell As Range, rng As Range

Set rng = Range("B1:B10")

For Each myCell In rng
If myCell = 0 and not isempty(mycell) Then
myCell.Offset(0, 1).Value = "LOW"
Else: myCell.Offset(0, 1).Value = "" '<==
End If
Next myCell

End Sub

Added a line to delete any "LOW" texts that are already there whe
script is started

--
Message posted from http://www.ExcelForum.com


JMay

Help with Loop
 
Thanks guys, for your help
I better understand what I was not doing (right)..


"Berend Botje " wrote in
message ...
Sub TryAgain()

Dim myCell As Range, rng As Range

Set rng = Range("B1:B10")

For Each myCell In rng
If myCell = 0 and not isempty(mycell) Then
myCell.Offset(0, 1).Value = "LOW"
Else: myCell.Offset(0, 1).Value = "" '<==
End If
Next myCell

End Sub

Added a line to delete any "LOW" texts that are already there when
script is started.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 07:22 PM.

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