Solved

How to modify my VBA code to select a range that will stop on the first row that has no data?

Posted on 2016-09-23
3
31 Views
Last Modified: 2016-09-23
The below code works perfect, but the range is fixed.  Instead of range "L2:L2000" I want to make the range "l2: the last row with data".

Range(Sheet3.Range("L2:L2000").Find("No"), Sheet3.Range("L" & Rows.Count).End(xlUp)).EntireRow.Resize(, 10).Copy
Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues

Open in new window

0
Comment
Question by:kbay808
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41813188
  dim nRow2 As Long 
   With Sheet3 ' or sheet reference
      nLastRow  = .Cells(.Rows.Count, 12).End(xlUp).Row 'L is column 12
   End With

Open in new window

then use nLastRow instead of 2000 -->
"L2:L" & nLastRow

Open in new window

0
 

Author Closing Comment

by:kbay808
ID: 41813223
It worked great...  Thank you
0
 
LVL 19
ID: 41813230
you're welcome ~ happy to help
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

806 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