Go to next empty row, even with empty rows in between?

  • Thread starter StargateFanFromWork
  • Start date
S

StargateFanFromWork

I have this code that works perfectly on most spreadsheets as there are
usually no empty rows (most times there shouldn't be empty rows):
********************************************************************************************************
Sub AddNewEntry()
'
Dim iLastRow As Integer

ActiveSheet.Unprotect 'place at the beginning of the code

iLastRow = Range("A65536").End(xlUp).Row

If iLastRow <> 1 Then
Range("A" & iLastRow).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Offset(1, 0).Select
Else
Range("A2").Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, -1).Select
End If

ActiveSheet.Protect ' place at end of code
End Sub
********************************************************************************************************

But a new spreadsheet requires something a little different. I need to
leave blank lines in between "subjects", as it were. Though the "groupings"
are informal, it's been easier to keep things organized in this sheet this
way as the info is temporary and the information in these lists gets moved
around or deleted or changed. Is there a piece of code that can skip over
filled rows, re entries in column A, till the next empty row is reached. So
that it sort of jumps over filled rows to get to next empty row every time
we press the button?

Thanks! :blush:D
 
S

StargateFanFromWork

PCLIVE said:
Maybe something like this:

Range("A1").End(xlDown).Offset(1, 0).Select

Interesting. Unlike the code I posted below, this one doesn't go to the
first of the last set of empty rows at the very bottom of the print area, it
goes to the first empty row in column A. However, subsequently pressing the
button just keeps it in this spot, i.e., in the case, at cell A12 and it
doesn't do anything after that.

Here's the sheet as it stands now - (A1+A2=header), A3-A10=full,
A11-A15=empty rows, A16 has info in it, A17=empty, A18 full, A19 +
A20=empty, A21 full, A22-A24=empty, A25 full, last rows A26 to A31 empty.

It's probably easier if I give the example as for this case above, maybe.
The "toggle" button, or whatever we could call this, would jump first to
A11, then next press would take cursor to A17, next press to A19, next to
A22 and finally to A26.

Is this possible to do, though?

Thanks! :blush:D
 
P

PCLIVE

Try this:

If Range("A" & ActiveCell.Row).End(xlDown).Row = 65536 _
Then
Range("A65536").End(xlUp).Offset(1, 0).Select
Else
Range("A" & ActiveCell.Row).End(xlDown).Offset(1, 0).Select
End If
 
S

StargateFanFromWork

PCLIVE said:
Try this:

If Range("A" & ActiveCell.Row).End(xlDown).Row = 65536 _
Then
Range("A65536").End(xlUp).Offset(1, 0).Select
Else
Range("A" & ActiveCell.Row).End(xlDown).Offset(1, 0).Select
End If

YESSS! <g> This seems to work just perfectly, that's great. Excel makes
life so much easier, doesn't it??!!! Can't believe how easy it is to work
in and around this list now.

Thank you! :blush:D
 

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

Similar Threads


Top