Solved

VB Command to move cursor to first empty row of table

Posted on 2014-02-13
4
1,833 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
  • 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 33

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now