user3099425
user3099425

Reputation: 1

VBA in Excel - how to get a cell value if only condition is true in loop

enter image description here

how to get the only name which is colum B in cloum E when the status is > 0 in Excel VBA, please help out.

Upvotes: 0

Views: 5685

Answers (2)

engineersmnky
engineersmnky

Reputation: 29478

Simple Example and should be expanded to fit you needs

Sub CopyName() 
    Dim lcell AS Range
    For Each lcell in Range("$B$2","$B$15")
        If Cells(lcell.Row,lcell.Column + 1) > 0 Then
           Cells(lcell.Row,"E").Value = lcell.Value
        End If
    Next lcell 
End Sub

Upvotes: 1

Ashwin Balamohan
Ashwin Balamohan

Reputation: 3332

In Column E, you can paste the following:

=IF(B1>0, A1, "")

If column B has a value greater than 0, it will fill in column A's value. Otherwise, it'll fill in an empty string (i.e. nothing).

Upvotes: 0

Related Questions