Solved

Select to last row in a specific column

Posted on 2014-10-04
4
379 Views
Last Modified: 2014-10-04
Hi,

I have the following code that sets C2:C2000 as the range. 2000 is an arbitrary number and hopefully the data will never be more than 2000 rows. I'd rather set the range to the last cell in column C regardless how many rows of data are in the sheet.

Dim rng As Range, cell As Range, del As Range
Dim strCellValue As String
Set rng = Sheets("Sheet1").Range("C2:C2000")
For Each cell In rng
etc.
etc.
0
Comment
Question by:swjtx99
  • 2
4 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40361366
Set rng = Sheets("Sheet1").Range("C2:C" & Cells(Rows.Count, "C").End(xlup).Row)
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40361371
Here is the code:

Sub get_last_cell()

Dim last As Integer

With ActiveSheet
        lastRow = .Cells(.Rows.count, "C").End(xlUp).Row
End With

Dim rng As range, cell As range, del As range
Dim strCellValue As String
Set rng = Sheets("Sheet1").range("C2:C" & lastRow)


End Sub

Open in new window

0
 

Author Closing Comment

by:swjtx99
ID: 40361403
Hi Martinliss,

Exactly what I was looking for. As I have many of the same references in my code, I'll only have to change one line of code.

6 hours of googling = 0
1 post to EE and 5 min wait = 1

Thanks!

swjtx99
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40361427
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

24 Experts available now in Live!

Get 1:1 Help Now