0

I apologize if this is a stupid question but I can't get to figuring this one out.

What I want to do is import a .csv / .xlsx / .xls file and have a vba module auto-detect the range and do some cell formatting / apply filter etc. and eventually do a pivot.

Any help will be appreciated

Community
  • 1
  • 1
Roan
  • 9
  • 4
  • 2
    You probably need **UsedRange** – Gary's Student Jul 17 '15 at 15:31
  • 1
    Related: [How can I find the last row /or column/ that contains data in a specific column and on a specific sheet?](http://stackoverflow.com/questions/71180/how-can-i-find-last-row-that-contains-data-in-the-excel-sheet-with-a-macro). – user3819867 Jul 17 '15 at 15:39

1 Answers1

0

Gary's student is right.

Dim lRow as Long
Dim lCol as Long

lRow = ws.UsedRange.Rows.count
lCol = ws.UsedRange.Columns.count

Or

Dim r As Range
r = ws.UsedRange
MatthewD
  • 6,719
  • 5
  • 22
  • 41