variable range in a macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a worksheet where the number of rows and columns vary each time I
process the data.
I want to transpose the cols and rows but need to set the range before I
copy. There may not be any data in the XY cell. Is there a way to do this in
a macro?
Thanks for any help.
 
Hi Al,

Assume data starts in A1 and that there is a blank row below, and a blank
column to the right, of the data, then your data can be defined by:

ActiveSheet.Range("A1").CurrentRegion
 
LastRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row

LastCol = Cells(1, 256).End(xlToLeft)
 
or being consistent

LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top