LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Last Line Code: Let's Make This Better


Hey folks, I wrote this neato function, but it always takes a second or
two to complete all its loops. I sometimes run it on each page in a
workbook for various reasons and it slows me down.

The code starts analyzing the value in each cell from the bottom of a
worksheet, and gets the last line of data (using IsEmpty) in each
column. It does this for 100 columns but exits if it gets five blank
columns in a row.

I tried searching for a built-in function to accomplish the same task,
but could not. Anyone have any tips? I suppose I could write in a
couple of input boxes to have the user specify a smaller maximum line
to analyze, but I'm looking for something more elegant.

Function FindLastLine()
Dim x As Variant
Dim a, acount, maxx, c As Integer
On Error Resume Next

maxx = 0
For c = 1 To 100
a = 65537
Do
a = a - 1
x = Cells(a, c)
Loop Until IsEmpty(x) = False Or a = 1
If a maxx Then maxx = a
If a = 1 Then acount = acount + 1

'set the count threshold below to higher than 5 if your file has a lot
of blank lines
If acount 5 Then GoTo Exxxit
Next c
Exxxit:
FindLastLine = maxx
End Function


--
coctosten
------------------------------------------------------------------------
coctosten's Profile: http://www.excelforum.com/member.php...o&userid=28757
View this thread: http://www.excelforum.com/showthread...hreadid=484466

 
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
Macro code to put series name next to individual line in line grap Otani Charts and Charting in Excel 3 February 23rd 10 07:24 PM
How do I make a line graph WITHOUT first line starting at zero? NorthStar Charts and Charting in Excel 9 September 7th 07 02:31 PM
Make a line in a bar chart, and change color of any bars that exceed the line MarkM Excel Discussion (Misc queries) 4 July 5th 06 04:06 PM
How to make a button VBA code reference other VBA code subroutines??? gunman[_9_] Excel Programming 4 September 27th 05 01:01 AM
Code to make a New line in a message John Parham Excel Programming 2 September 18th 03 07:46 PM


All times are GMT +1. The time now is 03:20 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"