Check Whether a Range is Empty before Filling first Empty Cell in Range

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello,
Just starting off by saying thanks to Joe4.

In a prior thread I asked a question on how to fill the first empty cell in a range with the word "done". Joe4 gave the following answer which works great:

<code>
Sub CommandButton4_Click()

Dim dfR As Range

Set dfR = Sheets("Sheet1").Range("A13")

If dfR = "" Then
dfR.Value = "Done"
Else

If dfR.Offset(1, 0) = "" Then
dfR.Offset(1, 0).Value = "Done"
Else
dfR.End(xlDown).Select
If Selection.Row < 23 Then
Selection.Offset(1, 0).Value = "Done"
Else
MsgBox "Range A13:A23 is full!"
End If
End If​
End If

End Sub
</code>

I wanted to expand on this by adding a line that first checks whether range A13:I13 is empty
before filling the row. This must be offset with every loop until row A23:I23. I came up with the
following:

<code><code>
Sub CommandButton4_Click()

Dim dfR As Range
Dim rwRng as Range

Set dfR = Sheets("Sheet1").Range("A13")
Set rwRng = Sheets("Sheet1").Rows("13:13")

</code>
<code>If rwRng = "" then
</code>
dfR.Value = "Done"​
<code> Else
</code>
If rwRng.Offset(1, 0) = "" Then
<code> dfR.Offset(1, 0).Value = "Done"
</code>
<code> Else
</code>
<code> dfR.End(xlDown).Select
</code>
<code> If Selection.Row < 23 Then
</code>
<code> Selection.Offset(1, 0).Value = "Done"
</code>
<code> Else
</code>
<code> MsgBox "Range A13:A23 is full!"
</code>
<code> End If
</code>
<code> End If
</code>
<code> End If

End Sub
</code></code>
But it does not give the desired result. Can someone please help me?

Regards
Herman

 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
How about
Code:
Sub CommandButton4_Click()

    Dim Cnt As Long
    
    For Cnt = 13 To 23
        If WorksheetFunction.CountA(Range("A" & Cnt).Resize(, 9)) = 0 Then
            Range("A" & Cnt).Value = "Done"
            Exit For
        ElseIf Cnt = 23 Then
            MsgBox "Range A13:A23 is full!"
        End If
    Next Cnt

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top