From active cell, select NonBlank cells Up to first blank cell

julhs

Active Member
Joined
Dec 3, 2018
Messages
454
Office Version
  1. 2010
Platform
  1. Windows
This should be SO simple, but have got an utter mind blank!!
Just want to select the range from the active cell up to the FIRST occuring blank cell
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Not SO simple.

Explain what "blank cell" means, such as if nothing (nothing means nothing) is in that cell or maybe a formula returns a null string meaning that cell looks "blank" but really is not empty.

Explain what column this is or if it is a multi-column range.

Explain if you want a VBA solution or you want the manual steps.
 
Upvote 0
Thank for response Tom
"Blank" means completely empty
Single column, C
VBA, as looking to fit it into another routine
 
Upvote 0
If it helps.
C4 has value
C5 has value
C6 is BLANK
C7 has value
C8 has value
C9 has value
C10 is Active cell
Select C10:C7
 
Upvote 0
This should cover your bases, assuming the macro is executed when the active cell is in column 3.

Note the usual boilerplate proviso that you rarely need to select a cell or range in order to manipulate it. But your literal request was to select the range, so here it is.

VBA Code:
Sub Test()
Dim xRow As Long, LastEmptyRow As Long
If Len(ActiveCell.Offset(-1).Value) = 0 Then
xRow = ActiveCell.Row - 1
Else
For xRow = ActiveCell.Row - 1 To 1 Step -1
If Len(Cells(xRow, 3).Value) = 0 Then
LastEmptyRow = xRow
Exit For
End If
Next xRow
End If
Range(ActiveCell, Cells(xRow + 1, 3)).Select
End Sub
 
Last edited:
Upvote 0
Solution
Sorry for delayed response, been working on my primary code to incorporate of what you gave me.
It did what I asked and have tweaked my primary code to utilise it.
I appreciate your comment:
Note the usual boilerplate proviso
But due to my poor VBA knowledge/skills the way I overcame a problem in my primary code was to select the cell in question,
BUT this lead to the need for this post.
Have now got things working as I wanted.
Many thanks for your help
Julhs
 
Upvote 0

Forum statistics

Threads
1,221,494
Messages
6,160,141
Members
451,624
Latest member
TheWes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top