Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did not test but wonder if this would not work using a1 for last row
This has been thoroughly tested and works a peach for me to find the last row/col that contains data... Public Function GetLastDataPos&(Optional Wks As Worksheet, _ Optional IsRow As Boolean = True, Optional StartPos& = 1) ' Finds the last row or col of UsedRange that contains data. ' Allows for excluding any number of header rows/cols. ' ' Args: ' Wks Optional: ' Object ref to the sheet being searched. ' Defaults to ActiveSheet if missing. ' ' IsRow Optional: ' Boolean value that determines which axis to test. ' ' StartPos Optional: ' A type Long that specifies the start row/col of the search. ' If omitted the search starts at A1. ' Dim n&, k&, lLast& If Wks Is Nothing Then Set Wks = ActiveSheet With Wks.UsedRange lLast = IIf(IsRow, .Rows.Count, .Columns.Count) For n = lLast To StartPos Step -1 k = Application.CountA(IIf(IsRow, Wks.Rows(n), Wks.Columns(n))) If k 0 Then GetLastDataPos = n: Exit Function Next 'n End With 'Wks.UsedRange End Function -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Garry,
Can you give me a simple example of how to use the function? I start by copying to a standard module... then what do I do on the sheet? Howard |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Garry,
Can you give me a simple example of how to use the function? I start by copying to a standard module... then what do I do on the sheet? Howard It's this simple... Dim lLastRow&, lLastCol&, lNextRow&, lNextCol& lLastRow = GetLastDataPos() 'to return row# lLastCol = GetLastDataPos(IsRow:=False) 'to return col# OR LNextRow = GetLastDataPos() + 1 LNextCol = GetLastDataPos(IsRow:=False) + 1 ...where any extra blank rows residual in UsedRange doesn't matter because the function loops backwards until it finds a non-empty range. -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Thursday, November 27, 2014 9:46:51 AM UTC-8, GS wrote:
Hi Garry, Can you give me a simple example of how to use the function? I start by copying to a standard module... then what do I do on the sheet? Howard It's this simple... Dim lLastRow&, lLastCol&, lNextRow&, lNextCol& lLastRow = GetLastDataPos() 'to return row# lLastCol = GetLastDataPos(IsRow:=False) 'to return col# OR LNextRow = GetLastDataPos() + 1 LNextCol = GetLastDataPos(IsRow:=False) + 1 ..where any extra blank rows residual in UsedRange doesn't matter because the function loops backwards until it finds a non-empty range. -- Garry Okay, thanks. Off to play with it. Howard |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
But have some fun, eh!!
-- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
identical formula returns #VALUE! error | Excel Discussion (Misc queries) | |||
Series with named range on several identical sheets | Charts and Charting in Excel | |||
How to lookup when range contains multiple identical entries? | Excel Discussion (Misc queries) | |||
Inexplicable difference in row hiding speed - identical code, identical machines! | Excel Programming | |||
how do i get an error message if identical data is in two or more. | Excel Programming |