Solved

Select to last row in a specific column

Posted on 2014-10-04
4
385 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 47

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 47

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

734 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