Count no empty cells at the right of a selection

A

avi

Hello,

I am looking for a robust code that will count no empty cells at the
right of a selection

Using Range(Selection, Selection.End(xlToRight)).Select seems to
capture all the cells only the next block and not all the columns at
the right

Thanks
Avi
 
C

Claus Busch

Hello Avi,

Am Thu, 7 Jul 2011 09:58:50 -0700 (PDT) schrieb avi:
Using Range(Selection, Selection.End(xlToRight)).Select seems to
capture all the cells only the next block and not all the columns at
the right

try:
myCount = Selection.Cells.Count - _
WorksheetFunction.CountBlank(Selection.Offset(0, 1))


Regards
Claus Busch
 
G

Gord Dibben

Sub select_to_lastcolumn()
'select to last filled column in activerow, ignoring intermediate blanks
Range(ActiveCell, Cells(ActiveCell.Row, Columns.Count).End(xlToLeft)).Select
End Sub

What the code does is start from far right column then work back until it
reaches the first non-blank cell.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top