Solved

VB Command to move cursor to first empty row of table

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Formula 4 28
Search for a value in Column? 5 21
Hard coding time and date into Excel 2 30
macro for closing opened workbook 6 18
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

929 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

16 Experts available now in Live!

Get 1:1 Help Now