Solved

VB Command to move cursor to first empty row of table

Posted on 2014-02-13
4
2,080 Views
Last Modified: 2014-02-13
I am recording an Excel macro and need it to select the first empty field at the bottom of a particular column.  The number of rows in the column will vary every time I run the macro.  

I've figured out a way to have the macro move to the last row of data of the column with this command:

Selection.End(xlDown).Select

If column F has 8 rows of data, the above lands me on F8.  But I then need to move the cursor down one more row to F9.  When I use the macro recorder, Excel records a literal address of F9 like this:

Range("F9").Select

But the next time I run it column F might have 10 rows of data.  What command do I use to move down one?
0
Comment
Question by:witzph1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 39856603
Try something like this:

I= Selection.End(xlDown).Select
Range("F"& I+1).Range

Flyster
0
 
LVL 34

Accepted Solution

by:
Norie earned 500 total points
ID: 39856669
Try this.
Range("F" & Rows.Count).End(xlUp).Offset(1).Select

Open in new window

0
 

Author Closing Comment

by:witzph1
ID: 39857112
This gives does exactly what I need and does it in the most elegant fashion. Thank you!
0
 
LVL 22

Expert Comment

by:Flyster
ID: 39857941
I agree. Nice code imnorie!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question