jeudi 5 novembre 2015

Fill cell with text only if empty

I am trying to make a program which will fill column A with specific text. The text will depend on whether cells B43 onwards are filled with the text I would like to show up in column A.

This is what I have come up with:

Dim freecell As Range
Dim inforcells As Range

Set infocells = Range("A61:A90")

If Range("B43") <> "" Then
        For Each freecell In infocells.Cells
            If freecell = "" Then
               freecell.Value = "some text"
            End If
        Exit For
        Next
End If

If Range("B45") <> "" Then
        For Each freecell In infocells.Cells
            If freecell = "" Then
               freecell.Value = "some text"
            End If
        Exit For
        Next
End If

How do I format the for loop outside of the if statement so that it not only checks for the next empty cell in column A but also fills it with the text I want?

Aucun commentaire:

Enregistrer un commentaire