ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   first non blank cell (https://www.excelbanter.com/excel-programming/415446-first-non-blank-cell.html)

guest

first non blank cell
 
Hello, on clue on how to find first non blank cell in the columns selected.
For example; if user selects Column A and Column B I need to find first non
blank cell only in the column A and B.

thanks.

Ron de Bruin

first non blank cell
 
Hi guest

Try this

Sub test()
On Error GoTo BodemUp
Columns("A:B").Cells.SpecialCells(xlCellTypeBlanks ).Cells(1).Select
Exit Sub
BodemUp: Cells(Rows.Count, "A").End(xlUp)(2).Select
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"guest" wrote in message ...
Hello, on clue on how to find first non blank cell in the columns selected.
For example; if user selects Column A and Column B I need to find first non
blank cell only in the column A and B.

thanks.


Héctor Miguel

first non blank cell
 
hi, !

... on clue on how to find first non blank cell in the columns selected. For example;
if user selects Column A and Column B I need to find first non blank cell only in the column A and B.


for the first non blank cell in selected range... maybe something like...

On Error GoTo EmptyRange
With Selection ' Columns("a:b")
.Find("*", .Cells(.Rows.Count, .Columns.Count), xlValues, xlWhole, xlByRows).Select
Exit Sub
EmptyRange: MsgBox "It's an empty range !": .Cells(1).Select
End With

hth,
hector.



Rick Rothstein \(MVP - VB\)[_2532_]

first non blank cell
 
Not sure what you mean by "find"... this code will create a selection
composed of the first blank cell in each column of the original selection
(this original selection does not have to be the whole columns... you can
simply one or more cells in each column before running the code).

Dim C As Range
Dim Result As Range
For Each C In Selection.Columns
If Result Is Nothing Then
Set Result = C.Offset(1 - C.Row, 0).End(xlDown)
Else
Set Result = Union(Result, C.Offset(1 - C.Row, 0).End(xlDown))
End If
Next
Result.Offset(1, 0).Select

If you need to do something other than select the cells, the
Result.Offset(1, 0) range will contain all first blank cells in each
column... simply do something else besides selecting them.

Rick


"guest" wrote in message
...
Hello, on clue on how to find first non blank cell in the columns
selected.
For example; if user selects Column A and Column B I need to find first
non
blank cell only in the column A and B.

thanks.




All times are GMT +1. The time now is 02:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com