Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default max row and max col

How to find out the maximum row and col in the current worksheet without
going to the actual cell?

I know if i actually go to the last cell i can find out.

Selection.End(xlToRight).Select




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default max row and max col

Selection.End(xlDown).Row

and

Selection.End(xlToRight).Column

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Shinya Koizumi" wrote in message
...
How to find out the maximum row and col in the current worksheet without
going to the actual cell?

I know if i actually go to the last cell i can find out.

Selection.End(xlToRight).Select






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default max row and max col

This should work for you. It finds the right most populated column and bottom
most populeted row.

Public Sub LastCell(Optional ByVal wks As Worksheet)
Dim lngLastRow As Long
Dim intLastColumn As Integer

If wks Is Nothing Then Set wks = ActiveSheet
On Error Resume Next
lngLastRow = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
intLastColumn = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
If lngLastRow = 0 Then
lngLastRow = 1
intLastColumn = 1
End If
End Sub

--
HTH...

Jim Thomlinson


"Shinya Koizumi" wrote:

How to find out the maximum row and col in the current worksheet without
going to the actual cell?

I know if i actually go to the last cell i can find out.

Selection.End(xlToRight).Select





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default max row and max col

Dim app as Excel.Application

app.ActiveSheet.Rows.Count

worked for me

thanks

Shinya


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default max row and max col

Doesn't that just return 65536 every time?

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Shinya Koizumi" wrote in message
...
Dim app as Excel.Application

app.ActiveSheet.Rows.Count

worked for me

thanks

Shinya




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"