Solved

Select to last row in a specific column

Posted on 2014-10-04
4
386 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 48

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 48

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

623 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