detecting range of spreadsheet

A

altein

Hi,

I'm trying to design a simple spreadsheet that does some accountin
calculation and then represents them in a variety of charts. I'
simply using macros through demonstration rather than coding. I wa
wondering how one might be able to use VBA to detect the bottom righ
most range Y coordinate(X letter is predertimed - number of fields i
spreadsheet) so the macro will run correctly regardless of how man
rows there are?

Thanks ahead,
Altei
 
G

Gary''s Student

Here is some code to give the limits of UsedRange:

Set r = ActiveSheet.UsedRange

nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)

nLastColumn = r.Columns.Count + r.Column - 1
MsgBox ("last column " & nLastColumn)

nFirstRow = r.Row
MsgBox ("first row " & nFirstRow)

nFirstColumn = r.Column
MsgBox ("first column " & nFirstColumn)

numrow = r.Rows.Count
MsgBox ("number of rows " & numrow)

numcol = r.Columns.Count
MsgBox ("number of columns " & numcol)
 

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

Top