[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

check for data in last row

The following line checks for the last row of data by looking in column "A" only:

lastrow = Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row

My worksheet has 5 columns of data (columns A through E).  Not every cell will always contains data.  Therefore, on the last row, there could be times where, for instance, column B, C, D and E contain data but A does not.  I need to check all columns in the used range, not just column A, to determine the last row.  How do I modify the above code to do that?
0
dbfromnewjersey
Asked:
dbfromnewjersey
  • 2
1 Solution
 
GrahamSkanCommented:
There is a UsedRange property, so try:
lastrow = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count - 

Open in new window

1
0
 
GrahamSkanCommented:
I seem to have placed the '/code' markup in the wrong place. Here is a correction

There is a UsedRange property, so try:
lastrow = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count -  1  

Open in new window

0
 
dbfromnewjerseyAuthor Commented:
Thank you.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now