Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Smallest range on sheet containing non-blank cells?

Does anyone know of a quick VBA way of determining the smallest range
on the active sheet that contains all of the cells with data.
What I mean is:
Say the active sheet has data in only B4, F8 and H6; then the smallest
range containing these cells is B4:H8 and that is the range that I then
want to work with using the SpecialCells method.
I'm hoping I can avoid looping through an array of all the sheet's cell
values.
Any ideas or suggestions?
Ken Johnson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Smallest range on sheet containing non-blank cells?

Hi Ken,

Have you try small function? Goto excel help search and type "small"

SMALL(array,k)

Hope this helps.

"Ken Johnson" wrote:

Does anyone know of a quick VBA way of determining the smallest range
on the active sheet that contains all of the cells with data.
What I mean is:
Say the active sheet has data in only B4, F8 and H6; then the smallest
range containing these cells is B4:H8 and that is the range that I then
want to work with using the SpecialCells method.
I'm hoping I can avoid looping through an array of all the sheet's cell
values.
Any ideas or suggestions?
Ken Johnson


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Smallest range on sheet containing non-blank cells?

Worksheet.UsedRange.Address will give you the smallest used range of
cells.

SMALL(array,k) will give you the kth smallest value in an array of
values.

HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Smallest range on sheet containing non-blank cells?

Hi Ken,

Try something like:

'==================
Public Sub Tester01()
Dim rng As Range
Dim RngA As Range, RngB As Range
Dim RngBig As Range
Dim ar As Range
Dim WB As Workbook
Dim Sh As Worksheet
Dim CalcMode As Long

Set WB = ActiveWorkbook '<<========== CHANGE
Set Sh = WB.Sheets("Sheet1") '<<========== CHANGE
Set rng = Sh.UsedRange
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

On Error Resume Next
Set RngA = rng.SpecialCells(xlCellTypeConstants)
Set RngB = rng.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not RngA Is Nothing Then Set RngBig = RngA

If Not RngB Is Nothing Then
If Not RngBig Is Nothing Then
Set RngBig = Union(RngB, RngBig)
Else
Set RngBig = RngB
End If
End If

If Not RngBig Is Nothing Then
For Each ar In RngBig.Areas
'do something, i.e.:
ar.Copy Destination:= _
WB.Sheets("Sheet4").Range(ar.Address)
ar.Interior.ColorIndex = 6
Next ar
End If

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub

'<<==================

---
Regards,
Norman


"Ken Johnson" wrote in message
oups.com...
Does anyone know of a quick VBA way of determining the smallest range
on the active sheet that contains all of the cells with data.
What I mean is:
Say the active sheet has data in only B4, F8 and H6; then the smallest
range containing these cells is B4:H8 and that is the range that I then
want to work with using the SpecialCells method.
I'm hoping I can avoid looping through an array of all the sheet's cell
values.
Any ideas or suggestions?
Ken Johnson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Smallest range on sheet containing non-blank cells?

Mel, Nick and Norman,
Thanks for your help.
You've given me heaps to experiment with!
Ken Johnson



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
Returning 2nd smallest value in a range Rachel7 Excel Worksheet Functions 9 February 13th 09 04:00 AM
Finding 2nd smallest number in range Rachel7 Excel Worksheet Functions 8 February 12th 09 02:33 PM
Maximum Number of Blank Cells between Non Blank Cells in a Range Mal Excel Worksheet Functions 5 November 3rd 07 08:21 AM
Formatting smallest number in a range? penglvr Excel Worksheet Functions 3 June 9th 06 05:27 PM
Getting the 2nd largest or smallest valuesin a range Michael Rekas Excel Discussion (Misc queries) 5 January 31st 05 07:48 AM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"