macro select next blank cell in a row

G

Guest

Hi, I'm trying to do a macro that will automaticly select the first blank
cell that will appear in a row, I have tried the following but it doesn't
select the cell but my message box will give me the right cell adress for the
empty cell.

Sub A()
Dim myCell As Range
Dim NextEmpty As Range

Set myCell = ActiveSheet.Range("c5")
Do
If myCell.Value = "" Then
Set NextEmpty = myCell
Exit Do
Else
Set myCell = myCell.Offset(0, 1)
End If
Loop

MsgBox NextEmpty.Address

End Sub
 
D

Dave Peterson

Change:
MsgBox NextEmpty.Address
to
nextempty.select

But for lots of things, you don't have to select the range to work with it:

with nextempty
.value = date
.numberformat = "mm/dd/yyyy"
end with

(If I wanted the date in that cell.)
 
D

Doug

Add NextEmpty.Select in the line before or after the MsgBox
line.


Doug


raph_baril wrote in message
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top