Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default automatically finding the first empty cell

Hi newsgroup,

I hope you can help me with some VBA challenge:

I do have a range named "demand" starting at "B15" and ending somewhere
variably - it has one column and around 800 rows...

My problem is that I need to know which cell of the range is the first empty
cell - therefore it would be perfect if excel can give me the relative
reference, so to say : the xxxth cell counted from the top cell is empty...

Does anyone know a possible solution?

Of course I could use a loop but it would be very bad because the macro is
long enough and if he checks every cell it would take some more minutes...
and time is money ;o)

Very heavy thanks in advance and best regards,


Markus


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default automatically finding the first empty cell

Hi Markus

firstEmptyCell = Range("B15").End(xlDown).Offset(1,0).Address

returns the address of that empty cell. But beware. it throws an error if
B16 is empty, so best to test for that explicitly and if so, bypass that
statement.

--
HTH

Bob Phillips

"Markus Scheible" wrote in message
...
Hi newsgroup,

I hope you can help me with some VBA challenge:

I do have a range named "demand" starting at "B15" and ending somewhere
variably - it has one column and around 800 rows...

My problem is that I need to know which cell of the range is the first

empty
cell - therefore it would be perfect if excel can give me the relative
reference, so to say : the xxxth cell counted from the top cell is

empty...

Does anyone know a possible solution?

Of course I could use a loop but it would be very bad because the macro is
long enough and if he checks every cell it would take some more minutes...
and time is money ;o)

Very heavy thanks in advance and best regards,


Markus




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default automatically finding the first empty cell

Here is a function that does it You can get the logic from there.

Sub Main()
MsgBox ShowEmpty(Range("Demand"))
End Sub

Function ShowEmpty(rng1 As Range)
Dim rng As Range
'Application.Volatile
Set rng = Nothing
'Set rng1 = Range("demand")
If IsEmpty(rng1(1)) Then
Set rng = rng1(1)
ElseIf IsEmpty(rng1(2)) Then
Set rng = rng1(2)
Else
Set rng = rng1(1).End(xlDown)(2)
End If
' now rng holds a reference to the first empyt cell
' rng.row gives the row
' rng.row - rng1(1).row +1 gives the nth number
ShowEmpty = "absolute row: " & rng.Row & vbNewLine _
& "nth row: " & rng.Row - rng1(1).Row + 1
End Function

--
Regards,
Tom Ogilvy




"Markus Scheible" wrote in message
...
Hi newsgroup,

I hope you can help me with some VBA challenge:

I do have a range named "demand" starting at "B15" and ending somewhere
variably - it has one column and around 800 rows...

My problem is that I need to know which cell of the range is the first

empty
cell - therefore it would be perfect if excel can give me the relative
reference, so to say : the xxxth cell counted from the top cell is

empty...

Does anyone know a possible solution?

Of course I could use a loop but it would be very bad because the macro is
long enough and if he checks every cell it would take some more minutes...
and time is money ;o)

Very heavy thanks in advance and best regards,


Markus




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default automatically finding the first empty cell

Hi Bob,

firstEmptyCell = Range("B15").End(xlDown).Offset(1,0).Address

returns the address of that empty cell. But beware. it throws an error if
B16 is empty, so best to test for that explicitly and if so, bypass that
statement.


heavy thanks :o)

Best regards,

Markus



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default automatically finding the first empty cell

Hi Tom,

heavy thanks to you as well :o)

Have a nice day!


Markus



Function ShowEmpty(rng1 As Range)
Dim rng As Range
'Application.Volatile
Set rng = Nothing
'Set rng1 = Range("demand")
If IsEmpty(rng1(1)) Then
Set rng = rng1(1)
ElseIf IsEmpty(rng1(2)) Then
Set rng = rng1(2)
Else
Set rng = rng1(1).End(xlDown)(2)
End If
' now rng holds a reference to the first empyt cell
' rng.row gives the row
' rng.row - rng1(1).row +1 gives the nth number
ShowEmpty = "absolute row: " & rng.Row & vbNewLine _
& "nth row: " & rng.Row - rng1(1).Row + 1
End Function

--



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
Finding First Empty Cell in a Column TomHull Excel Discussion (Misc queries) 5 November 9th 09 01:19 AM
Finding First Empty Cell in a Column TomHull Excel Discussion (Misc queries) 0 November 9th 09 12:21 AM
Finding the first empty row with VBA Melker Excel Programming 4 October 22nd 04 08:02 PM
Finding first (end of range) empty cell Alesandro Senerchia Excel Programming 4 May 20th 04 02:36 AM
Finding the next empty cell. Unknown_User[_3_] Excel Programming 10 May 19th 04 02:45 PM


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