Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Find maximum row count of data

How would I find the last (bottom row) of data when data may be missing in
some columns? I'm trying to set Chart options on the run with macros instead
of setting the bottom row to a default value such as row 1000. The number of
rows is changing depending on options picked from a ListBox.
Thanks Steve
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Find maximum row count of data

Do you mean by using a worksheet formula? If so, do you have a column that
will always have data in the last row? If so, give this formula a try (where
I have assumed that column with data in the last row is A)...

=MATCH(LOOKUP(2,1/(A1:A65535<""),A:A),A:A,0)

Rick


"Steve" wrote in message
...
How would I find the last (bottom row) of data when data may be missing
in
some columns? I'm trying to set Chart options on the run with macros
instead
of setting the bottom row to a default value such as row 1000. The number
of
rows is changing depending on options picked from a ListBox.
Thanks Steve


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Find maximum row count of data

No Rick
I'm looking for a VB or macro solution so that I can change chart ranges on
the fly.

"Rick Rothstein (MVP - VB)" wrote:

Do you mean by using a worksheet formula? If so, do you have a column that
will always have data in the last row? If so, give this formula a try (where
I have assumed that column with data in the last row is A)...

=MATCH(LOOKUP(2,1/(A1:A65535<""),A:A),A:A,0)

Rick


"Steve" wrote in message
...
How would I find the last (bottom row) of data when data may be missing
in
some columns? I'm trying to set Chart options on the run with macros
instead
of setting the bottom row to a default value such as row 1000. The number
of
rows is changing depending on options picked from a ListBox.
Thanks Steve



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Find maximum row count of data

Again, if you have a column that will always have data in the last row of
your data, then you could do this (again assuming that column is A)...

LastRow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

If, on the other hand, there is no row always guaranteed to have data in it
for the last row of data, then you can use this function to get the highest
row number that contains data...

Function MaxRowInUse(Optional WS As Worksheet, Optional _
FactorInHiddenRows As Boolean = False) As Long
Dim X As Long
Dim LastRow As Long
If WS Is Nothing Then Set WS = ActiveSheet
With WS
For X = 1 To .UsedRange.Columns.Count
If Not (Not FactorInHiddenRows And Columns(X).Hidden) Then
LastRow = .Cells(.Rows.Count, X).End(xlUp).Row
If LastRow MaxRowInUse Then MaxRowInUse = LastRow
End If
Next
End With
End Function

Note: If you don't specify a worksheet in the first (optional) argument,
then the active sheet is used. The second optional argument is the
interesting one... it lets you determine whether to include hidden rows or
columns when determining the maximum row and column that are in use; that
is, if a hidden row or column contains the maximum row or column, it will be
ignored unless the second argument is set to True. This allows you to get
the maximum row or column for what you see on the worksheet rather than for
what what any hidden data would return. I wasn't sure which would be the
most logical default for this second argument, so I chose not factor in
hidden rows or columns (that is, the functions return the maximum row and
column for only the visible data); if desired, this can be easily changed in
the declaration headers for each function.

Rick


"Steve" wrote in message
...
No Rick
I'm looking for a VB or macro solution so that I can change chart ranges
on
the fly.

"Rick Rothstein (MVP - VB)" wrote:

Do you mean by using a worksheet formula? If so, do you have a column
that
will always have data in the last row? If so, give this formula a try
(where
I have assumed that column with data in the last row is A)...

=MATCH(LOOKUP(2,1/(A1:A65535<""),A:A),A:A,0)

Rick


"Steve" wrote in message
...
How would I find the last (bottom row) of data when data may be
missing
in
some columns? I'm trying to set Chart options on the run with macros
instead
of setting the bottom row to a default value such as row 1000. The
number
of
rows is changing depending on options picked from a ListBox.
Thanks Steve




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Find maximum row count of data

Thanks so much Rick. That should do it.

"Rick Rothstein (MVP - VB)" wrote:

Again, if you have a column that will always have data in the last row of
your data, then you could do this (again assuming that column is A)...

LastRow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

If, on the other hand, there is no row always guaranteed to have data in it
for the last row of data, then you can use this function to get the highest
row number that contains data...

Function MaxRowInUse(Optional WS As Worksheet, Optional _
FactorInHiddenRows As Boolean = False) As Long
Dim X As Long
Dim LastRow As Long
If WS Is Nothing Then Set WS = ActiveSheet
With WS
For X = 1 To .UsedRange.Columns.Count
If Not (Not FactorInHiddenRows And Columns(X).Hidden) Then
LastRow = .Cells(.Rows.Count, X).End(xlUp).Row
If LastRow MaxRowInUse Then MaxRowInUse = LastRow
End If
Next
End With
End Function

Note: If you don't specify a worksheet in the first (optional) argument,
then the active sheet is used. The second optional argument is the
interesting one... it lets you determine whether to include hidden rows or
columns when determining the maximum row and column that are in use; that
is, if a hidden row or column contains the maximum row or column, it will be
ignored unless the second argument is set to True. This allows you to get
the maximum row or column for what you see on the worksheet rather than for
what what any hidden data would return. I wasn't sure which would be the
most logical default for this second argument, so I chose not factor in
hidden rows or columns (that is, the functions return the maximum row and
column for only the visible data); if desired, this can be easily changed in
the declaration headers for each function.

Rick


"Steve" wrote in message
...
No Rick
I'm looking for a VB or macro solution so that I can change chart ranges
on
the fly.

"Rick Rothstein (MVP - VB)" wrote:

Do you mean by using a worksheet formula? If so, do you have a column
that
will always have data in the last row? If so, give this formula a try
(where
I have assumed that column with data in the last row is A)...

=MATCH(LOOKUP(2,1/(A1:A65535<""),A:A),A:A,0)

Rick


"Steve" wrote in message
...
How would I find the last (bottom row) of data when data may be
missing
in
some columns? I'm trying to set Chart options on the run with macros
instead
of setting the bottom row to a default value such as row 1000. The
number
of
rows is changing depending on options picked from a ListBox.
Thanks Steve




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


Similar Threads
Thread Thread Starter Forum Replies Last Post
find data based on conditon of a maximum date gcmontgomery30 Excel Discussion (Misc queries) 4 August 7th 08 08:50 PM
?How can I find the maximum column with condition SAM SEBAIHI Excel Discussion (Misc queries) 4 February 9th 07 05:53 AM
Find Maximum date sgl Excel Worksheet Functions 3 February 15th 06 08:02 AM
find maximum Frank Drost Excel Discussion (Misc queries) 7 January 18th 06 02:23 AM
find which column has the maximum value Frank Drost Excel Discussion (Misc queries) 2 December 15th 05 01:09 AM


All times are GMT +1. The time now is 04:59 PM.

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"