Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Command to move cursor to first empty row of table

Posted on 2014-02-13
4
Medium Priority
?
2,203 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 35

Accepted Solution

by:
Norie earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

885 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