check range with Excel VBA

Posted on 2015-01-06
Last Modified: 2015-01-06
How can I use VBA dynamically determine the code. The number of rows may change, eg D20, D31...

Question by:AXISHK
  • 2
LVL 48

Expert Comment

ID: 40533371

pls try

Sheet1.Range(Range("A2"), Range("D" & Cells.Rows.Count).End(xlUp))

LVL 18

Assisted Solution

SimonAdept earned 200 total points
ID: 40533375
Or use this if you only want the contiguous block of cells starting from A2:
Dim rng As Range
Set rng = Range(Cells(2, 1), Cells(2, 4).End(xlDown))
LVL 48

Accepted Solution

Rgonzo1971 earned 300 total points
ID: 40533408
Or if the D cell could be empty but not the cell A in last row

Sheet1.Range(Range("A2"), Range("D" & Range("A" & Cells.Rows.Count).End(xlUp).Row))

Author Closing Comment

ID: 40534877

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now