Solved

FIND THE FIRST NON BLANK CELL IN A RANGE

Posted on 2014-12-03
9
81 Views
Last Modified: 2016-07-06
i am trying to find the first blank cell in range $F$15:$L$17  starting from f15,f16,f17 etc. thanks
0
Comment
Question by:Svgmassive
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40478718
Shortcut keystrokes:  Put your cursor in F15, then press [End] and then the [Down Arrow] key.

If you're looking for another solution (function or programmatic), please provide more specifics.

Regards,
-Glenn
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40478730
I also need to point out that your question title states "non blank cell" but your question says "first blank cell".  We'll need to know which one you really want if you're looking for another solution.
0
 

Author Comment

by:Svgmassive
ID: 40478741
example attached.
thank you
first-blank.xlsb
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 46

Expert Comment

by:Martin Liss
ID: 40478752
Dim r As Range
Set r = Range($F$15:$L$17).SpecialCells(xlCellTypeBlanks)
MsgBox r.Row

Open in new window

0
 

Author Comment

by:Svgmassive
ID: 40478777
sorry martin not what i am looking for
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 250 total points
ID: 40478784
Tweaking Martin's code (missing quotes) to show all addresses with blanks:
Sub Blank_List()
    Dim r As Range
    Set r = Range("$F$15:$L$17").SpecialCells(xlCellTypeBlanks)
    MsgBox r.Address
End Sub

Open in new window


However, if you want the address of the first blank cell of a range when scanned first by rows, then columns, this code will provide the address:
Sub First_Blank()
    Dim rng As Range
    Dim cl As Object
    Dim intRow As Integer
    For intRow = 15 To 17
        Set rng = Range("$F$" & intRow & ":$L$" & intRow)
        For Each cl In rng
            If IsEmpty(cl) Then
                MsgBox cl.Address
                Exit Sub
            End If
        Next cl
    Next intRow
    'no blank found - message
    MsgBox "No empty cells found in the specified range.", vbExclamation + vbOKOnly, "Notice"
End Sub

Open in new window


If you removed the For intRow = 15 to 17 loop and selected the entire range, the For Each...Next would scan by columns, then rows, returning $G$15 instead.

Regards,
-Glenn
EE-first-blank.xlsm
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 40478838
I assume you are wanting this as part of another script so that you can get it to enter a value into the first blank cell in the range.

If so how about for this logic:

Start at F15 - Do "End Right"  
If active column is less than 12 you haven't reached L, go one more right and populate as required;
If column is 12 (or greater) you have reached L (or beyond) so move back to F16 and repeat;
repeat for row 17 if required.

Thanks
Rob H
0
 
LVL 5

Accepted Solution

by:
Hakan Yılmaz earned 250 total points
ID: 40482451
I attach a sample with a custom function that gives the address of first blank cell in given range. First looks at columns and then rows.
first-blank.xlsb
0
 
LVL 5

Expert Comment

by:Hakan Yılmaz
ID: 41682694
I noticed a mistake in attached file. (It was working, but for different range).
Updated function is below.

Option Explicit

Function firstblankinrange(ByRef myrange As Range) As String
    Dim itercol As Integer
    Dim iterrow As Integer
    For itercol = 1 To myrange.Columns.Count
        For iterrow = 1 To myrange.Rows.Count
            If myrange.Cells(iterrow, itercol).Value = "" Then
                firstblankinrange = myrange.Cells(iterrow, itercol).Address
                Exit Function
            End If
        Next iterrow
    Next itercol
End Function

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Formula 5 46
Excel IF formula 3 21
Error 1004: Application-defined or object-defined error 10 17
Excel - remove duplicates 1 13
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question