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 49

Expert Comment

ID: 40533371

pls try

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

LVL 18

Assisted Solution

Simon 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete texts with font color 16 30
Copy value from a certain cell 5 24
Error in VBA for exact date format as in source file 9 16
Dynamic Filter ? 3 0
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 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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

914 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

13 Experts available now in Live!

Get 1:1 Help Now