Filling the first empty cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm new to VBA with excel, so be gentle. I'm having trouble writing a loop to go down a column and find the first empty cell and then fill it with a value from my form. I think I have the logic down, but I keep getting errors so I thought an example would be helpful. Thanks
 
Rick

Not sure if you mean "first" blank row or "first" blank row at bottom? Could
be different.

To copy B1 to first empty Cell at bottom of column A use this.

Sub Copyit()
Range("B1").Copy Destination:= _
ActiveSheet.Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)
End Sub

To copy B1o first blank Cell in Column A use this.

Sub Copyit22()
Range("B1").Copy Destination:= _
ActiveSheet.Cells.End(xlDown) _
.Offset(1, 0)
End Sub

Gord Dibben Excel MVP
 
Dim rng as Range
set rng = Cells(1,1)
do while not isempty(rng)
set rng = rng.offset(1,0)
Loop

would loop down the row as you described.

if the data is contiguous you could do

Dim rng
set rng = cells(rows.count,1).End(xlup)
if not isempty(rng) then set rng = rng.offset(1,0)

--
Regards,
Tom Ogilvy





Rick said:
I'm new to VBA with excel, so be gentle. I'm having trouble writing a
loop to go down a column and find the first empty cell and then fill it with
a value from my form. I think I have the logic down, but I keep getting
errors so I thought an example would be helpful. Thanks
 

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

Back
Top