Solved

VB Command to move cursor to first empty row of table

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple Open Excel Spreadsheets 12 41
how to delete specific files and folders with VBA 3 25
VBA Works in Excel 2010 Not 2016 Help! 5 20
Excel error  #DIV/0! 7 18
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

778 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