Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mel, Nick and Norman,
Thanks for your help. You've given me heaps to experiment with! Ken Johnson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Returning 2nd smallest value in a range | Excel Worksheet Functions | |||
Finding 2nd smallest number in range | Excel Worksheet Functions | |||
Maximum Number of Blank Cells between Non Blank Cells in a Range | Excel Worksheet Functions | |||
Formatting smallest number in a range? | Excel Worksheet Functions | |||
Getting the 2nd largest or smallest valuesin a range | Excel Discussion (Misc queries) |