Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select to last row in a specific column

Posted on 2014-10-04
4
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

715 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