ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   select populated cells (https://www.excelbanter.com/excel-programming/311222-select-populated-cells.html)

Kevin

select populated cells
 
i hate to ask this, because i'm sure it's come up a
million times before, but i've searched high and low and
couldn't find anything:

how do you select all of the populated cells of a
worksheet?

Tom Ogilvy

select populated cells
 
Dim rng1 as Range, rng2 as Range, rng3 as Range
On Error resume next
set rng1 = Activesheet.Cells.SpecialCells(xlconstants)
set rng2 = Activesheet.Cells.SpecialCells(xlFormulas)
On Error goto 0
if not rng1 is nothing and not rng2 is nothing then
set rng3 = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng3 = rng1
elseif not rng2 is nothing then
set rng3 = rng2
End if
if not rng3 is nothing then
rng3.Select
End if

--
Regards,
Tom Ogilvy

"Kevin" wrote in message
...
i hate to ask this, because i'm sure it's come up a
million times before, but i've searched high and low and
couldn't find anything:

how do you select all of the populated cells of a
worksheet?





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

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