P T
P T

Reputation: 3

If empty cell then fill another cell by value from third cell - loop

The situation:

In cells "D18:D94" and "E18:94" I have dropdown lists (data validation). In an additional sheet "Sheet2" in cells "R18:94", I have a formula.

Output wanted:

If cell "E18" is not empty then insert the value from "Sheet2!U18" to cell "F18". I want to loop this for each row from range.

I made something like this, but I don't know how to loop.

If Sheets("Sheet1").Range("E18").Value <> "" Then 
    Sheets("Sheet1").Range("F18").Value = Sheets("Sheet2").Range("R18")
End if

I don't want to set formula in Sheet1! "F" column because I have a dynamic print area.

Upvotes: 0

Views: 478

Answers (1)

Harun24hr
Harun24hr

Reputation: 36965

Try below sub-

Sub FillData()
Dim sRng As Range, Rng As Range
Set sRng = Sheets("Sheet1").Range("E18:E94")

    For Each Rng In sRng
        If Rng.Value <> "" Then
            Rng.Offset(0, 1).Value = Sheets("Sheet2").Range("R" & Rng.Row)
        End If
    Next Rng
    
Set sRng = Nothing
End Sub

Upvotes: 1

Related Questions