Solved

Select to last row in a specific column

Posted on 2014-10-04
4
376 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 45

Accepted Solution

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

Expert Comment

by:Haris Djulic
Comment Utility
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
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

771 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

11 Experts available now in Live!

Get 1:1 Help Now