Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Find first non-blank cell

Excel XP, Win Vista
I have a table of formulas that produce blank cells on condition. To set
the print range I want to find the first non-blank cell in Column A looking
from the bottom up.
Doing End(xlUp) will hit on the first formula cell (looking up) and not the
first non-blank cell. Looping up through Column A looking for a value of
not zero will find what I want.
Question: Is there a better way? Thanks for your time. Otto

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Find first non-blank cell

Dim rng As Range

Set rng = Range("C" & Rows.Count).End(xlUp)
Set rng = rng.End(xlUp)


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Otto Moehrbach" wrote in message
...
Excel XP, Win Vista
I have a table of formulas that produce blank cells on condition. To set
the print range I want to find the first non-blank cell in Column A
looking from the bottom up.
Doing End(xlUp) will hit on the first formula cell (looking up) and not
the first non-blank cell. Looping up through Column A looking for a value
of not zero will find what I want.
Question: Is there a better way? Thanks for your time. Otto



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Find first non-blank cell

Slight correctrion

Dim rng As Range

Set rng = Range("C" & Rows.Count).End(xlUp)
Do Until rng.Value < ""
Set rng = rng.End(xlUp)
Loop


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Otto Moehrbach" wrote in message
...
Excel XP, Win Vista
I have a table of formulas that produce blank cells on condition. To set
the print range I want to find the first non-blank cell in Column A
looking from the bottom up.
Doing End(xlUp) will hit on the first formula cell (looking up) and not
the first non-blank cell. Looping up through Column A looking for a value
of not zero will find what I want.
Question: Is there a better way? Thanks for your time. Otto



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Find first non-blank cell

Here is some code that leverages find...

Sub test2()
MsgBox LastCell(rng:=Sheet1.Range("B:B")).Address
End Sub

Public Function LastCell(Optional ByVal wks As Worksheet, Optional rng As
Range) As Range
Dim lngLastRow As Long
Dim lngLastColumn As Long

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

End Function
--
HTH...

Jim Thomlinson


"Otto Moehrbach" wrote:

Excel XP, Win Vista
I have a table of formulas that produce blank cells on condition. To set
the print range I want to find the first non-blank cell in Column A looking
from the bottom up.
Doing End(xlUp) will hit on the first formula cell (looking up) and not the
first non-blank cell. Looping up through Column A looking for a value of
not zero will find what I want.
Question: Is there a better way? Thanks for your time. Otto


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Find first non-blank cell

Bob, Jim
Thanks for the help. Otto
"Otto Moehrbach" wrote in message
...
Excel XP, Win Vista
I have a table of formulas that produce blank cells on condition. To set
the print range I want to find the first non-blank cell in Column A
looking from the bottom up.
Doing End(xlUp) will hit on the first formula cell (looking up) and not
the first non-blank cell. Looping up through Column A looking for a value
of not zero will find what I want.
Question: Is there a better way? Thanks for your time. Otto




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
Start Cell B1 then find first blank cell, insert subtotal, next non blank, then next blank, sutotal cells in between......... [email protected][_2_] Excel Programming 2 June 7th 07 09:27 PM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Find first blank cell Rui Excel Programming 5 November 20th 04 02:31 PM
find next blank cell Nancy[_4_] Excel Programming 2 April 22nd 04 09:06 AM
Find and blank cell then Do this..... Bonnie[_5_] Excel Programming 6 November 11th 03 04:35 PM


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

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

About Us

"It's about Microsoft Excel"