Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Curt D.
 
Posts: n/a
Default Go to first blank cell

Does anyone know how to find the first blank cell in a column using VBA. I
am running a macro and I want it to go to the first blank cell in a column
and count the number of cells above it that are not blank.
  #2   Report Post  
Harlan Grove
 
Posts: n/a
Default

"Curt D." <Curt wrote...
Does anyone know how to find the first blank cell in a column using VBA.
I am running a macro and I want it to go to the first blank cell in a
column and count the number of cells above it that are not blank.


Dim fnb As Range
Set fnb = Range("X1")
If Not IsEmpty(fnb.Value) Then
Set fnb = fnb.End(xlDown)
If fnb.Row < ActiveSheet.Rows.Count Then Set fnb.Offset(1, 0)
End If

If cell X1 is blank, it's the first nonblank cell. If all cells in col X are
nonblank, this will set fnb to X65536, but you'll have to check whether it's
blank.


  #3   Report Post  
Curt D.
 
Posts: n/a
Default

Thanks for the help Harlan, how would this be written in VBA if I want the
first blank cell in column A to count all the no blank cells above it?

"Harlan Grove" wrote:

"Curt D." <Curt wrote...
Does anyone know how to find the first blank cell in a column using VBA.
I am running a macro and I want it to go to the first blank cell in a
column and count the number of cells above it that are not blank.


Dim fnb As Range
Set fnb = Range("X1")
If Not IsEmpty(fnb.Value) Then
Set fnb = fnb.End(xlDown)
If fnb.Row < ActiveSheet.Rows.Count Then Set fnb.Offset(1, 0)
End If

If cell X1 is blank, it's the first nonblank cell. If all cells in col X are
nonblank, this will set fnb to X65536, but you'll have to check whether it's
blank.



  #4   Report Post  
Harlan Grove
 
Posts: n/a
Default

Curt D. wrote...
Thanks for the help Harlan, how would this be written in VBA if I want

the
first blank cell in column A to count all the no blank cells above it?

....

If you want the first blank cell in col A to become a cell with a
formula counting the preceding nonblank cells, you could try


Dim fnb As Range

Set fnb = Range("A1")

If IsEmpty(fnb.Value) Then
Set fnb = fnb.End(xlDown)

If fnb.Row = ActiveSheet.Rows.Count Then
MsgBox Prompt:="Column A is *ENTIRELY* blank. Nothing to count."
Set fnb = Nothing
End If

End If

If Not fnb Is Nothing Then
Set fnb = fnb.End(xlDown)

If fnb.Row < ActiveSheet.Rows.Count Then
fnb.Offset(1, 0).Formula = "=COUNTA(A1:" & fnb.Address(0, 0) & ")"

Else
MsgBox Prompt:="No blank cell below nonblank cells in which to
enter count."

End If

End If

  #5   Report Post  
Curt D.
 
Posts: n/a
Default

That worked Harlon, thanks.

"Curt D." wrote:

Does anyone know how to find the first blank cell in a column using VBA. I
am running a macro and I want it to go to the first blank cell in a column
and count the number of cells above it that are not blank.

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
Cell set to wrap text and blank line -- fix? Fred Holmes Excel Discussion (Misc queries) 0 January 25th 05 07:10 PM
COPY A CONCATENATE CELL TO BLANK CELL PUTTING IN THE NEXT BLANK C. QUEST41067 Excel Discussion (Misc queries) 1 January 15th 05 09:29 PM
conditional formatting blank cell TREK5200 Excel Discussion (Misc queries) 1 December 6th 04 02:23 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
VLookup resulting in a blank cell... KempensBoerke Excel Worksheet Functions 1 October 28th 04 09:57 PM


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